Peter Sylvester's post reminded me (for no reason I can identify) of something
else I do in any language that doesn't have an EXIT DO statement. Most
languages don't, at least not the ones I've encountered. REXX can do it for
controled loops, but not for a simple do. Come to think of it, the same for
VBA. Yet it can be very handy.
For example, something like this:
/* is this a user we want to process? */
do
if name='' then exit do /* no */
if st<>'NC' then exit do /* no */
amount=GetAmount(userID)
if amount>9999 then exit do /* no */
call ProcessUser; end
A SELECT won't do it, if I cannot invoke GetAmount until the user has passed
the first two tests (and certainly I'd rather not anyway). But I can do this:
/* Is this a user we want to process? */
do 1 /* once */
if name='' then leave /* no */
if st<>'NC' then leave /* no */
amount=GetAmount(userID)
if amount>9999 then leave /* no */
call ProcessUser; end
Now it's an iterated block, and I can use the LEAVE statement. In VBA I have
to work a little harder:
' Is this a user we want to process?
Do 'once
If name = "" Then Exit Do 'no
If st <> "NC" Then Exit Do 'no
amount = GetAmount(userID)
If amount > 9999 Then Exit Do 'no
ProcessUser
Loop While False 'or Loop Until True
I was insufferably pleased with myself when I invented this -- only, of course,
to discover eventually that other coders do it too.
---
Bob Bridges, [email protected], cell 336 382-7313
/* One hundred percent of the shots you don't take don't go in. -Wayne Gretzky
*/
-----Original Message-----
From: IBM Mainframe Discussion List <[email protected]> On Behalf Of
Peter Sylvester
Sent: Saturday, June 19, 2021 01:25
4 - Most languages use patterns like (add DO/BEGIN/{ }/END around f indented
lines
try something;
IF successful
THEN
blabla
ELSE
try something else
IF successful
THEN
I'd prefer
IF
try something
successful
THEN
blabla
ELSEIF
try something else
successful
THEN
which in a loop gives
WHILE
try next
more to do
LOOP
....
ENDWHILE
instead of in some puristic (non exit if or leave )
try next (actually first)
WHILE
more to do
LOOP
....
try next
ENDWHILE
At GMD where I worked since I was 20, worked with and on a structured
programming assembler macro set. (CBTTAPE 1005) Hm, should update this after 40
years.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN