Frank,

It should be quite easy to achieve what you want by introducing user-written 
FUNCTIONs, callable by name [i.e. NOT via CALL "xyz" verb]  

Consider the below code:   

PERFORM PROCESS-MY-RECORD
    UNTIL GET-NEXT-REC(NEXT-RECORD) = 0
END-PERFORM

Here GET-NEXT-REC is a FUNCTION name which returns the number of gotten records 
on a subsequent read attempt [either 0 or 1] and when successful also populates 
a passed area with the just read record.

This is how I was coding this type of logic in the old PL/I for DOS.

Unfortunately, with all new features Cobol still does not allow for such syntax 
[unless I missed the enhancement].
 
-Victor-

======================================================================
Hi, it's me.


My general thoughts are:

- This type of syntax is supported in a host of other programming languages. 
(see below for examples)

- Is it really confusing?  For me its more confusing doing all the things that 
I've done up to this point because COBOL (prior to the 2002 standard) did not 
allow me to do what I really wanted.

- I also think the elimination of procedure division SECTIONS and the 
"performing" of multiple paragraphs (PERFORM...THRU) by using these new 
features can be quite a benefit, rather than an issue.  Now will some people 
use/misuse these constructs within the context of sections and PERFORM THRU.  
Certainly.  But any programming language syntax can be misused.  That doesn't 
mean they should be eliminated (well, except for the ALTER statement, perhaps!).

- In the end, to me these new language features *enhance* structured 
programming.


https://www.rosettacode.org/wiki/Loops/Break

break: C and its followers (C++, Java, C#), Delphi, JavaScript, Ruby, Python

leave: PL/I and REXX

last: Perl

exit: Ada

EXIT PERFORM: COBOL

https://www.rosettacode.org/wiki/Loops/Continue
continue: C and its followers (C++, Java, C#), Delphi, JavaScript, Python
iterate: PL/I and REXX
next: Perl, Ruby
[not supported]: Ada
EXIT PERFORM CYCLE: COBOL


I can't find a Rosetta Code page for early exit/return from a 
procedure/function, but I believe the following are true:

return: C and its followers (C++, Java, C#), Delphi, JavaScript, Ruby, Python, 
PL/I, Rexx, Perl

EXIT PARAGRAPH / EXIT SECTION: COBOL


Should COBOL have added new keywords instead of co-opting/enhancing EXIT?  I 
don't think so.  Really, EXIT as COBOL defines it should never have existed.  
If they wanted a word to represent the end of a procedure they should have used 
the work END!  (And they did in the 85 standard support END PROGRAM, so why not 
END PARAGRAPH (too wordy, but...) and END SECTION.  Oh well!)


One of my favorite examples of the use of EXIT PERFORM is the "elimination" of 
"priming reads".  It's bugged me for 20 years (my COBOL lifetime).  To me, the 
following is ideal


PERFORM UNTIL EXIT *> Not currently part of the COBOL standard!!!  :-(

    READ MY-FILE INTO MY-RECORD

    AT END

        EXIT PERFORM

    NOT AT END

        PERFORM PROCESS-MY-RECORD

    END-READ

END-PERFORM


Here you have a read/process loop until such time as the read "fails", 
whereupon you exit/terminate the loop.

Unfortunately "PERFORM UNTIL EXIT" is not part of the COBOL standard (though it 
is supported as an extension by some implementations), so you have to come up 
with a dummy field that will "never be true" (in which case the compiler can 
optimize away the check), or your code can "check it twice" (once after the 
read and once at the top of the loop), which is redundant.


Those are my thoughts for now.  I have plenty more if anyone is interested.

:-)

Frank

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to