Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Loops
Message
From
04/04/2007 17:15:00
 
 
To
04/04/2007 11:12:53
Walter Meester
HoogkarspelNetherlands
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Re: Loops
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01211796
Message ID:
01212217
Views:
13
>>>>>>>Does a scan endscan loop exit at the bottom of the loop or at the top?
>>>>>>
>>>>>>It goes from top to bottom.
>>>>>
>>>>>Yes, that's right. But, a do while loop loops and at the end it exits the loop at the top. I believe that a for next loop runs and exits at the bottom.
>>>>
>>>>I don't see why it's important. One should not write code based on these assumptions. Either you exit loop specifically (by Exit) or you don't care.
>>>
>>>I was under the impression that if you have an EXIT in there, then the alogorythm isn't really designed "properly".
>>
>>You got wrong impression. There are real cases when you cannot fit all conditions into While expression. What are you going to do then? Continue to loop unnecessarily regardless that result already found?
>
>Can you give an example ? I can't see any case where it technically is not possible. I do regard avoiding LOOP and EXITa good practise, however I tend to use them with FOR EACH commands as there is no real easy way arround it, other than using an IF condition that takes out the meat of the inner code if a certain condition is set to true. In that case I see an EXIT a better alternative.

Well LOOP and EXIT do exist for a reason, and in general they are also restricted to "loop" sequences (you cannot use EXIT to get out of a subroutine, for example, you have to be within a "loop").

EXIT in particular was a very bad problem when languages supported the command in the early days of programming because it could be used to go out of subroutines mid-stream (as COBOL did). But since 'structured programming' became the norm that usage was "outlawed". And I think it was a consequence of that that has some people considering EXIT as bad form to this day. You know... people hear a rule and apply it indiscriminately.

But as I said, they are there for a reason - because they are helpful in making more efficient and more readable programs today. Anything can be mis-used, and DraganN certainly gave a situation that would be such.

cheers
Previous
Reply
Map
View

Click here to load this message in the networking platform