Guided Notes

Conditions: if, else & switch

Branching with if / else if / else, the ternary operator, switch with break and default, and if-with-initializer.

if, else if, else

Slide 1 / 5

if (score >= 90) { grade = 'A'; } else if (score >= 80) { grade = 'B'; } else { grade = 'C'; }

The first true branch runs and the rest are skipped, so order matters: check the most specific conditions first. Always use braces — a missing brace means only the next statement belongs to the if.

← Math & User Input