Using Loop Constructs
The four loop forms
while tests the condition before the first iteration, so the body may run zero times. do-while tests after, so the body always runs at least once and ends with a semicolon. The classic for (init; condition; update) allows multiple comma-separated expressions in init and update. The enhanced for (Type v : arrayOrIterable) hides the index and cannot remove elements or resize a collection while iterating (ConcurrentModificationException).
Scope rules
A variable declared in the for header is not visible after the loop. In a do-while, a variable declared inside the body is not available in the condition - different from while, where a variable declared before the loop is. Local variable names may not collide with an inner block's declaration.
break, continue, labels
break leaves the nearest loop or switch; continue skips to the next iteration. A label placed before a loop permits break outer; to exit nested loops - labels can only precede loops and blocks. In a switch inside a loop, break exits only the switch.
Traps
A stray semicolon after a for or while header creates an empty body and often an infinite loop. Conditions must be boolean, so while (1) will not compile. Code after while (true) with no break is unreachable and fails compilation. Classic off-by-one: for (int i = 0; i <= a.length; i++) throws ArrayIndexOutOfBoundsException.
Rule of thumb
Ask two questions about any loop: how many times does it run (check < vs <= and the update step), and what is the value of every variable after the final iteration.
Worked example
for (int i = 0, j = 5; i < j; i++, j--) { } runs three times (i=0/j=5, i=1/j=4, i=2/j=3) and stops when i=3, j=2.