Lesson 11
50 XP

If Statements

Making Decisions in Code

If statements let your program make decisions! The code inside only runs IF a condition is true.

Real Life Example:

IF it's raining outside,

THEN take an umbrella

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

How It Works:

  • if - The keyword that starts the condition
  • (age >= 18) - The condition to check
  • { } - Code block that runs if true