O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nested if Statements

An if-else statement lets you choose between just two different sets of actions. But sometimes, life presents us with three or more alternatives. Fortunately, the definition of an if-else statement allows you to nest if statements inside each other and thereby let a program choose between as many alternative actions as your mind can comprehend.

An if statement, as the name implies, is a statement in itself. Consequently, it can be positioned inside another if statement in the position where a statement is expected or as one of the statements in a compound statement. This is illustrated in Figure 8.5, which is based on the syntax of the if-else statement from Syntax Box 8.3.

Figure 8.5. Creating nested if statements.

Let's ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required