in reply to
Re: Re: Re: Re: for loop localisation bug?
in thread for loop localisation bug?
Sorry, but I think you are wrong on this. Checking both K&R (the original version from circa. 1978) and the ANSI C specification, particularly Scopes of identifiers and Iteration statements, I can find nothing to support your position.
Identifiers in C are block scoped, the iterator variable in a for loop must be declared prior to the for loop and there is nothing special about it. It retains the last value set until that value is changed, regardless of whether the statement that changed it is a simple assignment, inside or outside of a loop body, or even as one of the three statements that make up the for loop control statements. It remains in scope and defined until the block at which it was defined is exited.
It is never undefined, and any such statement of 'best practice' is simply ignoring both the design specification and the realities of implementations. It buys you nothing.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail