Thuta Learning
BasicProgrammingbeginner

If...Else

Relax. We'll talk through this in plain words — no textbook voice.

if...else is used when you need to check whether a condition is true or false and run a different code path accordingly. You'll run into this decision logic constantly — checking login access, whether a mark is a pass, whether stock is available, and so on.

csharp
int mark = 75;

if (mark >= 80)
{
    Console.WriteLine("Distinction");
}
else if (mark >= 40)
{
    Console.WriteLine("Pass");
}
else
{
    Console.WriteLine("Fail");
}

Condition flow

  • First it checks mark >= 80. If that's false, it moves on to the next condition.
  • mark >= 40 is true, so it prints Pass as the output.
  • Only when none of the conditions above are true does it fall into the else block.
You should see
Pass

Info

💡 Practical use

You'll reach for if...else all the time — checking user roles, payment status, whether form input is valid, and more.

If...Else | Thuta Learning