[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advanced Programming Structures



"Keith Olson" <s p a m t r a p 0 0 7 @ y a h o o . c o m> wrote:

> Hi gang!  I just came across a few notes from a programming class that I
> taught a decade or so ago.  Check this out:
> 
> DO ... LOOP UNTIL X<>0
> 
> is the same as
> 
> FOR II = 0 TO 1
>     ...
>     II=1
>     IF X=0 THEN II=0
>     IF Y=0 THEN II=9
>     IF Y=99 THEN II=10
> NEXT II
> IF II=10 THEN PRINT "AT BOTTOM"
> IF II=11 THEN PRINT "AT TOP"
> 
> Neat, eh?  A controlled loop w/o any GOTOs needed *AND* exit codes to boot!

Avoiding GOTOs is a means to clearer program structure, not an end in
itself. In a language that doesn't have REPEAT-UNTIL or DO-WHILE loops,
it is clearer to use a GOTO to emulate such constructs (possibly adding
a comment) than to pervert a FOR-NEXT loop. Look at your "improved" code
above: the central idea of repeating something until X<>0 is buried among
assignments to an artificial variable II. In programming as in writing,
one should say what one means.

Paul Guertin
pg@sff.net