← Java Programming learning path
Java Programming · Module 3 of 10

Operators, conditions and loops

Control program flow with if, switch, for, while and do-while.

📖 Key ideas

  1. if / else if / else choose a path.
  2. switch selects by value; modern Java has switch expressions with ->.
  3. for (int i = 0; i < n; i++) repeats a known number of times.
  4. while and do-while repeat on a condition.
  5. Enhanced for: for (String s : names) visits each item.
💡 Real-life example: Loops are like a teacher calling roll: go through each student until the list ends.
switchChooses a branch by value
Enhanced forLoops over each element
do-whileRuns at least once
&&Logical AND