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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.