Next: Omitted for-Expressions, Previous: for Statement, Up: Loop Statements [Contents][Index]

`for`

Here is the `for`

statement from the iterative Fibonacci
function:

int i; for (i = 1; i < n; ++i) /* If`n`

is 1 or less, the loop runs zero times, */ /* since`i < n`

is false the first time. */ { /* Nowlastis`fib (`

andi)previs`fib (`

. */ /* Computei- 1)`fib (`

. */ int next = prev + last; /* Shift the values down. */ prev = last; last = next; /* Nowi+ 1)lastis`fib (`

andi+ 1)previs`fib (`

. But that won’t stay true for long, because we are about to incrementi)i. */ }

In this example, `start` is `i = 1`

, meaning set `i`

to
1. `continue-test` is `i < n`

, meaning keep repeating the
loop as long as `i`

is less than `n`

. `advance` is
`i++`

, meaning increment `i`

by 1. The body is a block
that contains a declaration and two statements.