C++ Decision Making
, a
, a
Decision Statements
, a
| statement | Description |
|---|---|
| if statement | aif statement: |
| if...else statement | aif statementcan be followed by an optionalelse statementThe else statement is executed when the boolean expression is false. |
| Nested if Statements | You can in aiforelse ifuse another within the statementiforelse ifstatement. |
| switch statement | aswitchThe statement allows testing a variable for equality with multiple values. |
| Nested switch Statements | You can in aswitchuse another within the statementswitch statement. |
? : operator
We have already explained in the previous chaptersConditional Operator ? :, can be used to replaceif...elsestatement. Its general form is as follows:
Exp1 ? Exp2 : Exp3;
Here, Exp1, Exp2, and Exp3 are expressions. Note the use and position of the colon.
The value of the ? expression is determined by Exp1. If Exp1 is true, then the value of Exp2 is evaluated, and the result is the value of the entire ? expression. If Exp1 is false, then the value of Exp3 is evaluated, and the result is the value of the entire ? expression.
other extensions