Forum Navigation
You need to log in to create posts and topics.

FOR loop

Posted by: Waverly <Waverly@...>

>Wow, that makes sense. No wonder I could never do well in English. 🙂
>Oh...and about the whole for loop execution thing....the way I understood
>it was that since the for loop definition is actually a conditional, the
>code in the loop would not be executed if the conditional is false. For
>example:
>
>FOR X = Y TO Z 'no STEP
> uhhhh...like..some code and stuff
>NEXT
>
>If Y was greater than Z, and STEP by default was +1, then the code should
>never be executed, just like:
>
>LONG IF X = Y
> some more code
>END IF
>
>The "some more code" would not be executed if X = Y was false.
>
>Now if FB implements FOR loops so that they're executed at least once
>regardless of this, I believe that's wrong and Staz should be hanged :).
>I guess the only work-around, if it actually cause there to be a bug in
>one's program, would be to put a LONG IF around the FOR loop.
>
>Is this correct?

The FOR loop is not conditionally executed code. Just think about it for a
moment

FOR myLoop = 4 to 1
'do something in here
NEXT

FOR indexVar = expr1 TO expr2 [STEP expr3]
[statements]
NEXT [index1]

the index variable is set then tested for equality. If the index variable
is not equal to expression2 then it is incremented or decremented as the
case may be on the next iteration. The loop terminates the index variable
can no longer go to the next [STEP] value.

in the case above where myLoop equalled 4 the loop executed but because on
the next iteration it myLoop could not be assigned the next STEP value the
loop terminated.

A FOR loop is similar to a DO loop. It just takes less work to implement a
FOR loop.

W.

................................................................................

"If the only tool you have is a hammer, then every solution looks like a nail."
Abraham Maslow

The only time you should look down on a man is when you're helping him get up.

................................................................................