The C + + selection statement includes the IF statement and the switch statement:
if (condition) statement;
if (condition) statement Else statement;
Switch (condition) statement
comparison operator = =,! =, <, >=, <=.
The comparison value is true to return the bool value true, otherwise the bool value is returned as false.
Example of an IF statement:
if (a >= b) {
max = A;
} else {
max = b;
}
It's better to write the following:
Max = (a >= b)? A:B;
Switch can be another form of an if statement:
Switch (val) {
Case 1:
Do1 ();
Break
Case 2:
Do2 ();
Break
Default
Error ();
Break
}
Attention:
1. The four basic types of char, short, int, long, and bool can be used for switch statements.
2. Float, double cannot be used with a switch statement.
3. The enum type, that is, the enumeration type can be used for the switch statement.
4. All types of objects cannot be used with switch statements.
Declaration in a conditional statement:
In order to avoid errors using unexpected variables, it is a good idea to introduce variables in the smallest scope, for example:
if (double tempd = Prim (val)) {
Left/= tempd;
}
3. SELECT statement