>>>>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.