![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
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 ratio
is above 30
, but
also want to assign 1
to a suitable variable so as to record that
the ratio has gone above the threshold of 30:
if (ratio > 30) { high_ratio_switch = 1; printf ("It is expensive! High ratio switch set to %i.\n", high_ratio_switch); }