For loop: for (for-init statement condition; expression)
statement
The for-statement is intended to express fairly regular loops. A for loop
usually consists of
loop variable, the termination condition, and the expression that updates
the loop variable. We
are considering the following things to restrict and to watch out for to
guarantee the for
loop can be performed in polynomial time.
The case where the initializing statement can be empty.
If the condition is empty, the for-statement will loop forever unless it
exits by a
break, return, goto. A bad example:
for ( ; ; )
{
expressions
}
If the expression is omitted, we must make sure if the loop variable is
updated in the body of the loop.
For example:
for (i = 0; i <= 10; )
{
i++;
}
If the loop variable is updated in the expression, it shouldn't be updated
again in the body of the loop.
An obvious mistake can be made as this example:
for (i = 0; i <= 10; i++)
{
i--;
}
If the comparison operator in the condition is `>=' or `>', then the
loop
variable should be incremented.
If the comparison operator is `<=' or `<', then the loop variable
should
be decremented.
Loop variables are not allowed to be assigned to a pointer. And, pointers
are not allowed to be used as
loop variables.