Branching with the if Statement

The if statement comes in different varieties. We will first look at the very basic if statement version (termed the simple if statement) with which you are already familiar.

The Simple if Statement

The syntax of the simple if statement is displayed in Syntax Box 8.1.

Syntax Box 8.1 Simple if-Statement

							Simple_if-statement::=
                       if(<Boolean_expression>)
                           <Statement>;
						

Note

Recall from Chapter 6 that a Boolean expression is always evaluated to one of the two bool values—true and false.

The <Statement> immediately after the Boolean expression will only be executed if the Boolean expression of the if statement is evaluated ...

Get C# Primer Plus now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.