🔀 Control Flow
14 Java concepts, each explained step by step with real code, a common trap and practice questions.
- if / else if / elseBranching on boolean conditions.
- Blocks & variable scopeVariables live only inside their { } block.
- Dangling else & braceselse binds to the nearest if; why braces prevent bugs.
- Classic switch statementcase labels, fall-through without break, default.
- Switch expressionsArrow labels, no fall-through, yield, exhaustiveness.
- What you can switch onint-like types, char, String, enums, and any type with patterns.
- while loopCondition checked before each iteration; may run zero times.
- do-while loopBody runs at least once.
- for loopInit; condition; update, and off-by-one errors.
- Enhanced for-each loopIterating arrays and Iterables; cannot modify the index.
- break & continueExit the loop vs skip to the next iteration.
- Labeled break & continueExiting nested loops with labels.
- Infinite loops & unreachable codewhile(true), compiler unreachable-statement errors.
- Reading user inputScanner basics, nextInt vs nextLine pitfall.