I should offer a contrary opinion.
I support many sets of differently developed code with all my clients. When
properly indented, the EXIT is a logical way to conclude the visit in the
loop without labeling the REPEAT or introducing other DONE 'style'
variables. The code actually shrinks by a few lines. Example:
<Before>
GOOD.ANS=FALSE
LOOP UNTIL GOOD.ANS DO
PRINT "ENTER 'Y' OR 'N' ":;INPUT ANS
IF ANS="Y" OR ANS="N" THEN GOOD.ANS=TRUE
REPEAT
<after>
LOOP WHILE TRUE DO
PRINT "ENTER 'Y' OR 'N' ":;INPUT ANS
IF ANS="Y" OR ANS="N" THEN EXIT
REPEAT
Or my favorite code shrinking syntax:
<before>
EOF=0
LOOP
READNEXT ID ELSE EOF=0
UNTIL EOF DO
{process}
REPEAT
<after>
LOOP WHILE READNEXT ID DO
{process}
REPEAT
When I see code that has been heavily flagged I have to scratch my head.
EXIT and CONTINUE have been around at least as long as U2 has. I know that
they weren't there during the Jurrasic Pick era.
My 1 cent,
Mark Johnson
Maybe I follow poor programmers who got flag-crazy.
----- Original Message -----
From: "David A. Green" <[email protected]>
To: <[email protected]>
Sent: Friday, February 27, 2009 1:25 PM
Subject: RE: [U2] DO/WHILE vs IF THEN
> George,
>
> In my opinion you lose the elegance and readability of the LOOP construct
> when you use EXIT. Code is easier to debug and enhance when Loops and
> Subroutines have one entry and one exit.
>
> Thanks,
> David A. Green
> www.dagconsulting.com
> (480) 813-1725
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of George Gallen
> Sent: Friday, February 27, 2009 9:20 AM
> To: Ardent
> Subject: [U2] DO/WHILE vs IF THEN
>
> OK Aside from programming styles
>
> Is there any "functional" difference between
>
> WHILE expression DO and IF NOT(expression) THEN EXIT
> and
> UNTIL expression DO and IF expression THEN EXIT
>
>
> First I thought that the DO/WHILE would activate as soon as
> the condition occurred and drop out of a loop, but that is not
> the case, the condition has to be active AND control has to be
> back at the WHILE statement.
>
>
> Example:
>
> 0001: CTR=0
> 0002: LOOP
> 0003: CTR=CTR+1
> 0004: WHILE CTR<4 DO
> 0005: PRINT CTR
> 0006: CTR=CTR+1
> 0007: PRINT CTR
> 0008: CTR=CTR+1
> 0009: PRINT CTR
> 0010: CTR=CTR+1
> 0011: PRINT CTR
> 0012: CTR=CTR+1
> 0013: PRINT CTR
> 0014: CTR=CTR+1
> 0015: PRINT CTR
> 0016: CTR=CTR+1
> 0017: PRINT CTR
> 0018: REPEAT
> 0019: STOP
> 0020: END
>
> My first thought was that once CTR = 5, the loop would end (at LINE 12)
but
> it
> didn't
> until control was passed back to LINE 4, then it ended.
> -------
> u2-users mailing list
> [email protected]
> To unsubscribe please visit http://listserver.u2ug.org/
> -------
> u2-users mailing list
> [email protected]
> To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/