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

Multibranch if-else Statements

Notice how the value of balance in Listing 8.2 determines which of the five different print statements the program will execute. Letting the value of a variable determine which statement (or compound statement) to execute of several possible alternatives is so commonplace in the programming world that a standardized system has been devised for writing the nested if-else structures used to implement this functionality. The resulting structures are called multibranch if-else statements.

Let's have a look at how we can turn Listing 8.2 into this standard style. We start by changing the flowchart of Figure 8.10 to form a new flowchart that yields the same results but follows a couple of standard conventions:

  • Only the ...

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