Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Argument starter - The roots of all evil
Message
De
07/09/2004 12:04:08
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
07/09/2004 11:13:59
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00938079
Message ID:
00940004
Vues:
40
>>>>Surely you'd use a CASE statement though?
>>>
>>>Of course, but I've had cases where it wasn't enough. There may be a number of objects to be created, properties checked, and not all of them are having eliminating conditions, so there's the "heavy checking" phase at the top of the loop, then decision on whether to continue, then the beef.
>>
>>Then the "heavy" checking is decoupled to a proc/func.

In the case I remember, it already was. It's the sheer number of method calls which made it look heavy - the actual testing was far longer. But then, it's just the couple of cases where such things happen, which need special attention anyway.

>>>>>
>>>>lnLen = ALEN( this.aList, 1)
>>>>I = 1
>>>>Do while I <= lnLen ;
>>>>   and not EMPTY( lcValue)
>>>>	lcValue = prof_r( This.cSection, "row"+Transform( I), "", "C")
>>>>	If not Empty( lcValue)
>>>>		this.alist( I) = lcValue
>>>>         Else
>>>>                   I = I + 1
>>>>	EndIf
>>>>EndDo
>>>>
>>>
>>>Nice and not too much longer. You forgot one extra line, to initialize the lcValue to something not empty.
>
>For that matter - neither did you!!!

Of course I didn't - I didn't need to. The variable doesn't have to exist because it's not tested at the beginning of the loop :).

>>>> ... If speed was an issue, I'd think twice before doing the test (as simple as empty() function) twice each run of the loop.
>
>So I can cut it down to:
>
>I = 1
>Do while I <= lnLen ;
>  If EMPTY( lcValue)
>      I = lnLen
>  Else
>      lcValue = prof_r( This.cSection, "row"+Transform( I), "", "C")
>      this.alist( I) = lcValue
>      I = I + 1
>  Endif
>EndDo
>
>which is a bit of a frigg, short-circuiting I, but no more than putting in EXIT. I suppose a for loop could be similarly short-circuited too. However, I guess this is tantamount to EXIT anyway. I wonder if EXIT does something lke this in the compiler?

This is even more ugly than the original sin we are talking about :).
I think Exit just sets a "loop completed" bit, or does an "jump to first statement after the block" thing. I know it doesn't touch the control variable, because I remember I've used it to keep its value, i.e. to know how many times did it run.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform