next up previous
Next: A Loop Peeling Changer Up: Loop Peeling: An Example Previous: do

for

For for loops we'll cheat a little. We'll dismantle the following

        for (init; cond; next) body;

into the following equivalent:

        init;
        while (cond) {
                body;
                next;
        }

and then do the same transformation that we did for the while loop. Our transformation is incorrect if there is a continue in the body of the for loop, since continue doesn't mean the same thing for while as it does for the for statement.

(Note: C9X, the new ANSI C standard, will most likely allow init to be a variable definition with an initializer and scope limited to the for body, just like in C++; in this case, we will also need to enclose the new code in curly braces to limit the scope of init.)



Calvin Lin
2002-01-31