Lesson 5: Logical operators, else-if & switch
Last lesson we made a single decision with if and else; now we compose complex ones. The logical operators && (and), || (or) and ! (not) join several conditions into one. An else-if chain checks conditions one after another and runs only the first branch that holds. When comparing a single value aga
switch is like an elevator floor panel: you press a number and the elevator stops at exactly the matching floor. break is the door closing — without it you keep 'falling' into the next floor too.
- && (and)
- True only when both sides are true. (a > 0 && b > 0).
- || (or)
- True when at least one side is true.
- else-if chain
- Conditions are checked in order; only the first true branch runs.
- switch / case
- Compares a single value against fixed cases; default runs when nothing matches.
- break
- Exits the switch immediately. Without it, the flow falls through to the next case.