Skip to content
Justice Tech School

C# If and Else

if runs code when a condition is true. Add else if and else for more branches. A ternary condition ? a : b is a short form.

Example
int score = 72;
if (score >= 85) Console.WriteLine("Distinction");
else if (score >= 70) Console.WriteLine("Pass");
else Console.WriteLine("Retake");
Console.WriteLine(score >= 50 ? "ok" : "low");

Exercise

Second branch keyword.

if (a) {}  if (b) {}

Quiz Test

What is cond ? a : b?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.