|
![](/i/fill.gif) |
"Axel Baune" <aba### [at] neuro informatik uni-ulm de> wrote in message
news:38C8DAB2.3BE14CC3@neuro.informatik.uni-ulm.de...
>
> No, I don't think so. In most programming languages the state of the
> variables used in a for-loop are undefined outside the loop, but most
> programmers ignores this and use the mostly undocomented feature, that
> after the for-loop the variable has the value of the variable in the
> last loop incremented by the specified step.
Not really correct either. You are probably thinking of C++, where the
ISO/ANSI standard says that a variable declared (and initialized) inside
of the for-statement is defined only in the statement and the block that
belongs to it. A fact that is still ignored by most compilers (the
standard is still kind of fresh).
But:
This is true only for for-loops like this one:
for (int i = start; i != end; i++) {
}
If you rewrite the loop like this:
int i;
for (i = start; i != end; i++) {
}
then there is no ambiguity about if or if not "i" is defined after the
loop and which value it has. It *is* defined and *has* the value
assigned to it during the last executed operation that modified it.
Johannes.
Post a reply to this message
|
![](/i/fill.gif) |