While StatementsStatementsReturn StatementsIf Statements

If Statements

< if statement > -> if ( < expression > ) < statement part >
< else part >
< else part > -> else < statement part >
|
< statement part > -> { < statement list > }
| < statement >

Co does not recognize Boolean values as a separate type. Instead, it treats the integer value 0 as `false' and any non-zero value as `true'. Thus, to execute an if statement, the expression is first evaluated. It must evaluate to an integer. If its value is non-zero, the statement or statement list following the expression is executed after which execution resumes with the statement following the if statement. If the expression's value is zero and a non-empty else part was included, the statement or statement list found in the else part is executed. If the else part is empty and the expression's value is zero, then control simply passes to the statement after the if statement.


Computer Science 434
Department of Computer Science
Williams College

While StatementsStatementsReturn StatementsIf Statements