Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To iif or not to iif = .t.
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00513276
Message ID:
00514374
Views:
11
George,
... head for the bottom...
>Jim,
>
>Whoops, pressend Send rather than preview, lets try again.
>>I will pay the price when necessary because my personal preferences are (as regards this):
>>1) readable code;
>
>I'm fond of saying, "If it ain't readable, it ain't maintainable". Let me suggest that doing away with LOOP and EXIT can make code more readable. Consider the following:
DO WHILE   DO WHILE 
>  * Some code here             *Some code here
>  IF   IF NOT 
>    LOOP && or Exit             * This shows the logical subordination
>  ENDIF                         * of the code to the left
>  * This is logically          ENDIF
>  * sub-ordinate to the
>  * logical NOT of the above
>ENDDO                        ENDDO
I while this is a very simple sample, even so the code on the right is more readable to me than that on the right.
>
>>2) code that does not 'force' a condition (counter beyond value or condition now obviated) WITHIN A STRUCTURE (this is a problem in waiting);
>
>I'm not sure what you mean here. In some cases with Fox we have to simulate things we don't have. The post-test iteration structure for example. I'm not sure what you mean by "force". Testing for logical NOT, to me, isn't "forcing".
>
>>3) code that does not continue to process the loop condition when it is no longer necessary (IF condition(s) detects nothing more required so they do nothing but allow the natural loop to complete). This is just wasteful.
>
>True, and that's why iteration structures shoulld be properly terminated. With FOR...ENDFOR it mean means that the number of iterations are fixed and should not be subject to change. If the loop needs to conditionally terminate, then DO WHILE...ENDDO is required. Naturally, as I said to Nadya, there are exceptions, but it's important to program to the rules and handle the exceptions rather than the other way around.
>
>>Your preferences are what they are and mine are too. They both end up with working programs.
>
>Yes, I have preferences. However, I'm also keenly aware of the rules regarding programming technique. I don't consider these as such. They exist for a purpose, and in my experience and in my situation they do what they claim to do.

Acknowledging that your example is overly simplified, it's just fine for the LOOP condition (I would code the simpler cases this way too) but not so good for EXIT, as it essentially makes a forced completion of the WHILE. This could be very wasteful if processing records and there are more that satisfy the WHILE.

After your last I went on a brief search using GOOGLE to check out 'structured programming loop exit'. What was there was generally older (pertaining to when LOOP/EXIT (or similar) were introduced into various languages). Most entries said that they (LOOP/EXIT) were added to facilitated structured programming! A couple acknowledged that some contended that this was not in keeping with structured programming, but they seemd definitely in the (very) minority.

It tended to confirm in my mind that their usage was perfectly acceptable.

Cheers,

JimN
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform