next up previous contents index
Next: The #include construct. Up: A note on C++ Previous: Dynamically sized arrays.   Contents   Index

The form of the for statement.

The for statement in C (and C++) is more general than similar constructs in FORTRAN and Pascal. To repeat an operation n times, use:

for (int i$=$0; i$<$n; i++) {
some_operation(i)
}

The for statement has tree parts. The first part gives the initial condition (i=0). The next part the terminal condition ( i$<$n), which says to stop when i$<$n is not fulfilled, which is at the n'th iteration. The last part is the increment statement (i++), saying what to do in each iteration. In this case the value of i is increased by one in each iteration. This is the typical for statement, but one of the causes of C's reputation for terseness is the possibility of elaborate for constructs, which end up being almost impossible to read. In the algorithms presented here I try to only use the typical for statement, avoiding any obfuscated ones.


next up previous contents index
Next: The #include construct. Up: A note on C++ Previous: Dynamically sized arrays.   Contents   Index
Bernt Arne Odegaard
1999-09-09