Conditional Logic
Conditional Logic: If, Multiple Conditions, Switch, Switch Expressions.
Updated
- If (Novice): Use if, if-else and if-else if-else to run a block of code only when a condition is true, or to pick one block out of several.
- Multiple Conditions (Apprentice): Combine conditions with && (and) and || (or), and use parentheses to group them so the if means what you intend.
- Switch (Apprentice): The switch statement provides a more readable and efficient way to execute different code blocks based on the value of a single variable.
- Switch Expressions (Apprentice): Java's arrow switch never falls through, lets one case match several values, and can give back a value you store in a variable, with no break to forget.