You could do this.
PROCESS.REC:
************
READ RECORD FROM FILE,ID THEN
IF RECORD<FLD.1> EQ COND1 AND RECORD<FLD.2> EQ COND2 AND RECORD<FLD.3>
EQ COND3 THEN
RECORD<FLD.4> = 'PROCESSED'
WRITE RECORD TO FILE, ID
END IF
END IF
RETURN
The If statement is a little long, but there is one exit point, no nested
IF's, and less lines of code. I might even be tempted to put the IF
statement in the WHILE LOOP and not use a subroutine.
Is the IF statement to hard to read? I don't think so, but others might
disagree..
I do use multiple exit points sometimes, but I was trained not to and
avoid them unless there is a compelling reason. I suspect that they are
fine in the initial application, but someone else doing maintenance later
might miss something that the original author took for granted.
Charles Shaffer
Senior Analyst
NTN-Bower Corporation
"Womack, Adrian" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
11/29/2007 05:41 PM
Please respond to u2-users
To: <[email protected]>
cc:
Subject: RE: [U2] Deep and long indentations vs multiple exit
points
But this is so much easier to read (note the liberal use of blank lines
making the conditions easy to spot):
LOOP
WHILE READNEXT ID
GOSUB PROCESS.REC
REPEAT
RETURN
PROCESS.REC:
************
READ RECORD FROM FILE,ID
ELSE RETURN
IF RECORD<FLD.1> NE COND1
THEN RETURN
IF RECORD<FLD.2> NE COND2
THEN RETURN
IF RECORD<FLD.3> NE COND3
THEN RETURN
RECORD<FLD.4> = 'PROCESSED'
WRITE RECORD TO FILE, ID
RETURN
(hopefully the mail list didn't screw with the formatting)
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Marco Manyevere
Sent: Friday, 30 November 2007 1:46 AM
To: [email protected]
Subject: Re: [U2] Deep and long indentations vs multiple exit points
<snip>
I had to look up the "CONTINUE" statement. In 25 years I've never used
it, and don't even remember seeing it used. Now I know what it does I
think it should be banned.
</snip>
I use CONTINUE all the time when processing records that must meet
multiple conditions in a loop. This way my code doesnt look like 'flying
geese'. I will write:
LOOP WHILE READNEXT ID
READ RECORD
FROM FILE, ID ELSE CONTINUE
IF RECORD<FLD.1> NE COND1 THEN CONTINUE
IF
RECORD<FLD.2> NE COND2 THEN CONTINUE
IF RECORD<FLD.3> NE COND3 THEN
CONTINUE
RECORD<FLD.4> = 'PROCESSED'
WRITE RECORD TO FILE, ID
REPEAT
instead of:
LOOP WHILE READNEXT ID
READ RECORD FROM FILE,ID THEN
IF
RECORD<FLD.1> EQ COND1 THEN
IF RECORD<FLD.2> EQ COND2 THEN
IF RECORD<FLD.3> EQ COND3 THEN
RECORD<FLD.4> = 'PROCESSED'
WRITE RECORD TO FILE, ID
END
END
END
END
REPEAT
___________________________________________________________
Yahoo! Answers -
Got a question? Someone out there knows the answer. Try it now.
http://uk.answers.yahoo.com/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/
DISCLAIMER:
Disclaimer. This e-mail is private and confidential. If you are not the
intended recipient, please advise us by return e-mail immediately, and
delete the e-mail and any attachments without using or disclosing the
contents in any way. The views expressed in this e-mail are those of the
author, and do not represent those of this company unless this is clearly
indicated. You should scan this e-mail and any attachments for viruses.
This company accepts no liability for any direct or indirect damage or
loss resulting from the use of any attachments to this e-mail.
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/
This email was Anti Virus checked by Astaro Security Gateway.
http://www.astaro.com
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/