go to previous page   go to home page   go to next page

Answer:

Sure. It might consist of several boolean expressions combined with logic. However, the entire expression must return a single true/false value.


Implementing Alternation

IF example

In C and in most languages, alternation is implemented with an if-statement:

if ( condition )
  true branch
else
  false branch

With C, the condition evaluates to 0 or to non-zero. Zero is regarded as false and anything non-zero is regarded as true. Often, the branches are code blocks:

if ( condition )
{
  true block
}
else
{
  false block
}

Here is a small example:

/* disc contains the discriminant of a quadratic equation */
if ( disc >= 0.0 )
{
  compute real roots
}
else
{
  compute imaginary roots
}

QUESTION 11:

Is an if-endif (single alternative) structured?