Conditional Logic

Conditional Logic: If, Multiple Conditions, Switch, Switch Expressions.

Updated

  1. 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.
  2. Multiple Conditions (Apprentice): Combine conditions with && (and) and || (or), and use parentheses to group them so the if means what you intend.
  3. 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.
  4. 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.