×

c# · level 1 · unit 4 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

An if runs code only when its is true.

Picture a fork in the path with a sign asking a question. An if asks a condition like that, inside round brackets. If the answer is yes, C# runs the lines inside. If not, it walks straight past.

Every condition is true or false. A value that can only be one of these is a , and it can live in a box too. To ask whether two values match, use two equals signs, ==.

The lines that belong to the if sit in a , between curly brackets that each get a line of their own. Indent the lines inside by four spaces, so your eyes can see the block too.

using System;

int goals = 3;
Console.WriteLine(goals == 3);
if (goals == 3)
{
    Console.WriteLine("Hat-trick! Take a bow.");
}
Console.WriteLine("Full time.");

On the screen, C# shows a bool with a capital letter, as True or False.