Lesson 12
50 XP

Else & Else If

The Else Statement

The else statement runs when the if condition is false. It's the "otherwise" option!

Real Life Example:

IF you have money,

THEN buy the toy

ELSE

Save up for it

🎮 csharp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System; class Program{    static void Main()    {        int age = 15;         if (age >= 18)        {            Console.WriteLine("You are an adult!");        }        else        {            Console.WriteLine("You are not an adult yet.");        }    }}

Important:

  • Else must come after an if statement
  • Else doesn't have a condition - it catches everything else
  • Only ONE block runs: either if OR else, never both