Java While Loop
while repeats as long as a condition stays true. Check first. If the condition is already false, the body never runs. Shape: while (condition) { body }.
Something inside the body must move toward stopping — i++, or a new input — or the loop never ends. while is good when the count is not known: keep reading until the user types stop.
for is better with a counter. while is better with “until this becomes false”. Contrast with do-while: while can run zero times; do-while runs at least once.
Let's take this on the board with one tiny Main class — no extra files. Java While Loop — output: 1 then 2 then 3. i starts at 1. When i becomes 4, i<=3 is false — loop stops. Start from main, go line by line, and stop at each print. That output is the proof for While Loop.
check first ── false → stop
│ true
▼
body
│
└── check againContrast while (check first) vs do-while (body first).