If-Else Statement

A statement that executes one of two code blocks depending on a condition.

What is an if-else statement?

A statement that executes one of two code blocks depending on a condition.

if(age < 21) {
    price = 14.99;
} else {
    price = 19.99
}

// statements with a single line of code
// can be written like this
if(age < 21) price = 14.99;
else price = 19.99;

Level: Novice · More C# terms at this level

Updated