<aside> 🔁
L2.1 — Loops and Arrays covers the three loop constructions in Java (while, do-while, for), their differences in condition-checking behaviour, infinite loops, and introduces arrays as fixed-size homogeneous storage with declaration, instantiation, assignment, retrieval, and the enhanced for-each loop.
</aside>
while loop — condition checked before each iterationdo-while loop — condition checked after each iteration (runs at least once)for loop — initialisation, condition, state change in one lineArrayIndexOutOfBoundsExceptionLoops allow us to repeat a block of code multiple times without copy-pasting.
Without loops: You'd need to write System.out.println("Hello"); 55 times for 55 hellos — fixed, inflexible, impossible for large counts.
With loops: A single block of code is repeated as many times as needed, and the number of repetitions can be dynamic.
Java has three loop constructions: while, do-while, and for. All three can achieve the same result — they exist because each is more natural and readable in different situations.