The Compound if . . . else Statement

Format of the compound if . . . else statement:


  if (<boolean expression>)
  {
    <statement>
    . . .
    <statement>
  }
  else
  {
    <statement>
    . . .
    <statement>
  }

Example code fragment:

if (denominator != 0)
{
    ratio = numerator / denominator;
    cout << "The ratio is " << ratio;
    cout << endl;
}
else
{
    cout << "Can't divide by zero.";
    cout << "The ratio is undefined.";
    cout << endl;

Next page
Previous page
Go to Lesson 7 index.


HTML by Jennifer Keiser.
Sponsored by Inspiration, the diagramming and outlining tool.