StatementsWhile StatementsFor Statements

For Statements

< for statement > -> for ( < assignment statement > ; < expression > ; < assignment statement > )
< statement part >

The syntax of the for statement in Co is based on the most common use of the corresponding statement in C rather than on the actual syntax of the C for statement. In particular, the first and third items in the header of the for can only be assignment statements.

The first step in the execution of a for statement is the execution of the first assignment in its header. After this is done, the expression included in the header is evaluated. If its value is 0, the execution of the statement is complete. Otherwise, the statement part is executed and the assignment included as the third component of the header is executed repeatedly until evaluation of the expression yields 0.


Computer Science 434
Department of Computer Science
Williams College

StatementsWhile StatementsFor Statements