A selection statement alters a program's execution flow by
selecting one path from a collection based on a specified controlling
expression. The if
statement and the switch
statement are selection statements.
Syntax |
 |
selection-statement ::= if (expression) statement if (expression) statement else statement switch (expression) statement
|
Examples |
 |
if (expression) statement: if (x<y) x=y; if (expression) statement else statement: if (x<y) x=y; else y=x; switch (expression) statement: switch (x) { case 1: x=y; break; default: y=x; break; }
|