Loops in Java
From the Java cheat sheet · Control Flow · verified Jul 2026
Loops
for, enhanced for, while, and do-while.
java
// Quick Reference
for (int i = 0; i < 5; i++) { ... }
for (String s : list) { ... } // enhanced for
while (cond) { ... }
do { ... } while (cond);💡 Prefer the enhanced for (for-each) when you do not need the index.
⚡ do-while always executes the body at least once before checking the condition.
📌 Labeled break/continue targets an outer loop - handy for nested iteration.
🟢 continue skips to the next iteration; break exits the loop entirely.
loopsiteration