Java Tutorial · Revision notes
Java Control Statements
Control statements decide which code runs and how many times. Java provides decision statements (if-else, switch), loops (for, while, do-while) and jump statements (break, continue). This chapter explains each with complete programs.
Quick revision
- if needs a boolean condition; else-if ladder runs only the first true branch.
- Compare strings with equals(), not ==.
- switch works with byte, short, char, int, wrappers, String and enum; missing break causes fall-through.
- Arrow switch (Java 14+) has no fall-through and can return a value; use yield in blocks.
- for = counted loop; while = condition first; do-while = body first, ends with semicolon.
- For-each loops over arrays and Iterables but cannot give the index.
- break leaves the nearest loop or switch; continue skips to the next iteration.
- Labels with break or continue control nested loops; Java has no goto.