Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exit nested FOR loops
Message
From
27/07/2007 14:53:46
Al Doman (Online)
M3 Enterprises Inc.
North Vancouver, British Columbia, Canada
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01244106
Message ID:
01244225
Views:
18
>>If you need to exit a loop before a fixed number of iterations, using DO WHILE can be easier to understand and more maintainable.
>>
>>I consider EXIT similar to a GOTO (the BASIC linenumber kind, not the xBASE command) and I never, ever use it. The same goes for LOOP.
>
>Do while would not help you to Exit :)

When I see someone else's code that contains a FOR, I'm expecting a fixed number of iterations. If there's an EXIT in the loop, it's an unpleasant surprise - I then have to backtrack through the loop code to figure out what led to the EXIT . Complex loop code may require separate EXITs scattered throughout the loop, making maintenance, enhancement and debugging difficult.

In contrast, a DO WHILE alerts the reader that a loop may end conditionally, and shows the control variables up front so they're in the back of the reader's mind while she follows the code.
DO WHILE Counter <= MaxCount AND FlagIsTrue
  ...
  FlagIsTrue = SomeLogic( )

  Counter = Counter + 1

ENDDO
EXIT, LOOP etc. basically create more exit points, which I personally strongly dislike: Message#836545
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform