Else

If/Else Statement

An if/else statement lets a program make decisions. It checks a condition and runs different code depending on whether that condition is true or false.

For a broader introduction to decision-making in code, see Conditionals.

        ┌─────────────┐
        │  condition  │
        └──────┬──────┘
          true │ false
       ┌───────┴───────┐
       ▼               ▼
  ┌─────────┐     ┌──────────┐
  │ if block│     │else block│
  └─────────┘     └──────────┘

If#

The simplest form is a single if. The block runs only if the condition is true. If it’s false, nothing happens.