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:
00116225
Views:
27
>>So maybe it could be stated that DO WHILE is preferred when the repetitive actions are of indeterminate duration or until a logical flag is set while FOR..ENDFOR is for situations where the number of actions is determined or can logically be determined as a number by program heuristics.
>
>Okay, guys, I've done a little testing. Here's what I get, each test doing one simple calculation (ntest = nloopvar * 5), 1,000,000 loops:
>
>1) FOR with no condition, 4.01 seconds
>2) WHILE, 8.60 seconds
>3) FOR with EXIT condition if nloopvar = 1,000,000 (so it will check in all iterations), 6.15 seconds
>
>Ran each several times, results are average.
>
>So we note that the FOR is faster even with a terminus condition, at least in a simple test...

Bruce,

Nice job, but I think that this underscores what I was getting at. Let's say that you've got an iteration structure that has to make a 1,000 iterations or less. Let's further assume the results you've posted (2 and 3, that is) are indicative of the performance. This means that there's going to be a maximum of about 2.5/1000 of a second difference. Assuming (there's that word again :-)) this, and given the choice between FOR and DO WHILE, I'd choose the latter for purposes of readability if the number of iterations aren't fixed and a conditional exit is required.

That's just me, however. In my situation (unlike yours) I almost never (never, say never) have such a high number of iterations that it becomes a factor.
George

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

Click here to load this message in the networking platform