if sequences
if statement:
// if statement
if (num1 == num2)
cout << "you are in the if statement";
// if else statement
if (num1 == num2)
cout << "you are in the if statement";
else // if statement is false
cout << "if statement is false";
// if-else-if construct
if (num1 > 100)
cout << "A";
else if (num1 > 90)
cout << "B";
else if (num1 > 80)
cout << "C";
else // all others must be false
cout << "D";
if block statement
if (num1 == num2){
cout << "you are in the if statement";
cout << "2nd statement in the block";
}
// if else block statement
if (num1 == num2){
cout << "you are in the if statement";
cout << "2nd statement in the block";
}
else {
cout << "if statement is false";
cout << "block statement - if statement is false";
}
nested statement
// nested if block statement
if (num1 == num2){
if (num1 > 100){
cout << "you are in the if statement A";
}
else{
cout << "you are in the if statement B";
}
} else {
cout << "if statement was false";
}
switch statement
// switch statement
int int_expression = 2;
const int expr_1 = 1;
const int expr_2 = 2;
const int expr_3 = 3;
const int expr_4 = 4;
switch (int_expression) {
case expr_1: cout << "you're in case 1" << endl;
break;
case expr_2: cout << "you're in case 2" << endl;
break;
case expr_3: cout << "you're in case 3" << endl;
break;
default: cout << "you're in the standard case" << endl;
break;
}