Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Coding Standards
Message
From
10/07/1998 16:54:38
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00115272
Message ID:
00116322
Views:
18
>>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.

Sure they are. I thought your trick (actually I thought it was a normal practice to take out of the loop any code that doesn't have to repeat) was intended to take the calculation out of an inner loop, which would still be evaluated once per iteration of the outer loop.

Then I saw that I haven't seen any outer loop. Well, it's Friday.

Anyway, I remember studying the inner workings of for/next loops in several languages; I've even summoned my VAX Basic compiler to supply the assembly listing, and - in all the cases I've tried, the limit value of the loop was stored internally somewhere before running the loop, and compared with the current value of the loop variable at loop entry point.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform