Home Segments Index Top Previous Next

280: Mainline

Suppose that you want to execute more than one statement when an if or if-else statement's Boolean expression is true or not true. You need only to combine the multiple statements, using braces, into a single compound statement.

{ 
statement 1 
... 
statement n 
} 

In the following if-else statement, for example, you not only want to display a message when the value of temperature is above 50°F, but also want to assign 1 to a suitable variable so as to record that the temperature has gone above the threshold of 50°F:

if (temperature > 50) { 
  high_temperature_switch = 1; 
  cout << "It is too warm!  High temperature switch set to " 
       << high_temperature_switch << endl; 
}