A loop repeats work for you. while checks first, do-while runs once before checking, and for packs the counter on one line.
1 while loop
Repeats its block while the condition stays true — check first, run after.
2 do-while loop
Runs the body once before any check — guaranteed at least one round.
3 for loop
A while loop with a built-in counter: start, condition and step sit on one line.
4 The exit rule
Something inside must push the condition toward false — or the loop never ends.
Decisions and repetition
while loop1Repeats its block while the condition stays true — check first, run after.
do-while loop2Runs the body once before any check — guaranteed at least one round. for loop3A while loop with a built-in counter: start, condition and step sit on one line.
The exit rule4Something inside must push the condition toward false — or the loop never ends.
4 building blocks make up Decisions and repetition
This flowchart matches a countdown program: while count > 0, print something, then count down.
process decision input / output start / end Two tabs, two loops: a for loop that sums 1..3 and a while loop that counts down to liftoff.
JVMThe JVM loads the LoopDemo class into memory.
Memory
no variables yet — press play
Console
output appears as the program runs…
A while loop with an if/else inside — trace it round by round before you guess.
Your predicted output — one line per console line
Hint: n % 2 is the remainder after dividing by 2 — a remainder of 0 means even. The loop stops once n reaches 5.
Click a term, then click its job to lock the pair.
5 conceptsTap a card to expand ?whiledrops into place
?do-whiledrops into place
?fordrops into place
?breakdrops into place
?continuedrops into place
01while checks first — its body may never run.
02do-while runs the body at least once, then checks.
03for packs start, condition and step into one line.
04% gives the remainder: n % 2 == 0 detects even numbers.
05break exits a loop early; continue skips to the next round.