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:
00115316
Views:
20
>>The use of the EXIT and LOOP keywords is prohibitted. I think that these are the xBase equivalent of GOTO.
>
>Hi George - I haven't found another way to get out of a huge FOR loop for certain mathematical searches. I don't possibly want to run the entire loop if a condition fails, for example:
>
>
>FOR ncount = 1 to 2**20
>...  some code
>if some condition fails
>   EXIT
>endif
>ENDFOR
>
I should have qualified that by saying unless a quantifiable reason exists. That always should be the only case in which the "rules" are broken.

But, let me answer question. I don't deal with the same type of data or same situations that you do. However, in those cases where a large numer of iterations are required, I've had success in re-examining the problem to see if there is a smaller subset that can be used.

However, when it comes to something like an finding an item in an ordered list, there's no demonstrable need for a FOR...ENDFOR structure, as opposed to a DO WHILE...ENDDO, provided the algorithm is efficiently written, regardless of the size of this list.

I certainly don't mean to pick, my friend, but your example brings a question to mind. If speed is so essential there, why do you force the system to re-evaluate the terminating expression (2**20 or 2^20) every time through the loop. You gain more speed by:
lnlast = 2 ^ 20
FOR ncount = 1 TO lnlast
  * The same stuff here
ENDFOR
>I know you can use WHILE with condition instead, but FOR is supposed to be faster, and I need speed for this stuff. Any alternatives?
>
Mostly I was referencing instances like one of the examples that appears in the VFP Developers Guide, where they re-evaluate FCOUNT() in a loop (same problem as above) and use EXIT to jump out of the loop. In most instances, no appreciable gain in speed is made.



>Also, I noticed at last Devcon not all were using 'l' prefix for locals any longer. Since there are, in theory, now only properties, parameters, and local vars, do we really still need the 'l' for local? Or is this heresy? :)

Simple a use (or lack thereof) of convention. Things like this I think are largely personal. The most important thing, as far as I'm concerned, is readability.
George

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

Click here to load this message in the networking platform