Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Exit nested FOR loops
Message
De
27/07/2007 14:53:46
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01244106
Message ID:
01244225
Vues:
19
>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform