Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Coding Standards
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00115272
Message ID:
00115363
Views:
20
>George,
>
>The For loop terminating is evaluated only once:
>
>
n = 100
>for i = 1 to terminus()
>   n = n + 1
>endfor
>? i
>
>function terminus()
>return n
>
>If it actually called it each iteration the above loop would never end. It instead prints out 101

David,

First of all, my friend, you've demonstrated again why I think so highly of you.
I made an assumption based on my knowledge of the inner workings other languages, where this is (or has been) the case (namely, that the function or expression is evaluated each time through). In fact, whatever occurs to the terminating value within the loop has no effect. In other words you can change the value of the terminator via an assignment and without impacting the number of iterations. Apparently (I checked) this has been the case ever since at least 2.5. It also explains, in part why FOR...ENDFOR loops are faster than DO WHILE...ENDDO.

Bruce, nevermind what I said before. I'll think I'll change my signature now.
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform