World 4 of 26 · Beginner

🔀 Control Flow

14 Java concepts, each explained step by step with real code, a common trap and practice questions.

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