next up previous contents
Next: 3.1.10.2 Loop Expressions Up: 3.1.10 Controlling the Program Previous: 3.1.10 Controlling the Program

3.1.10.1 Conditional Expressions

In an if statement the first expression_list is executed only if the result of the boolean_expression is true. Otherwise the optional second expression_list in the else clause is executed.

if ( boolean_expression ) {
   expression_list
}
else {
   expression_list
}

Example 3.8 gives a possible MDL implementation of the function $y = sin(x)/x$. Alternative implementations demonstrating more advanced features of MDL will be discussed in the following sections.

\includegraphics[width=0.6cm]{figures/exaLeft.eps}

if ( fabs(x) > eps ) {
   y = sin(x)/x;
}
else {
   y = 1.0;
}

Example 3.8: Conditional expressions



Robert Mlekus
1999-11-14