- Compound Operator
- Expression Operator
- Return Operator
- Conditional Operator if-else
- Ternary Operator ?:
- Switch Operator
- Loop Operator while
- Loop Operator for
- Loop Operator do while
- Break Operator
- Continue Operator
- Object Create Operator new
- Object Delete Operator delete
If-Else Conditional Operator
The IF - ELSE operator is used when a choice must be made. Formally, the syntax is as follows:
if (expression)
|
If the expression is true, operator1 is executed and control is given to the operator that follows operator2 (operator2 is not executed). If the expression is false, operator2 is executed.
The else part of the if operator can be omitted. Thus, a divergence may appear in nested if operators with omitted else part. In this case, else addresses to the nearest previous if operator in the same block that has no else part.
Examples:
//--- The else part refers to the second if operator:
|
See also
Initialization of Variables, Visibility Scope and Lifetime of Variables, Creating and Deleting Objects