Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Exit nested FOR loops
Message
 
 
À
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:
01244228
Vues:
22
>>>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

I see, thanks.

I'm not sure, though, how can we apply it to the original problem, though my first immediate idea was also to change two loops into do while (which I didn't propose).
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform