In Java, both while and do-while loops repeat a block of code as long as a condition is true. However, there is one critical difference between them: when the condition is checked.

Let's look at how they work using two simple code examples.

1. The Java While Loop

A while loop checks the condition before executing the code block. If the condition is false at the very beginning, the code inside the loop will never run.

int ticketCount = 0;