[comp.lang.rexx] Getting out of a do-until

jfh@cup.portal.com (Jack F Hamilton) (07/01/89)

I tried to post this before but I don't think I succeeded.  If you get it 
twice, please ignore one... 
-
I am working on a program with 2 nested DO loops:

   outerloop: do until (a=1)
                 /* stuff */
   innerloop:    do until (b=2)
                 /* more stuff */
                    end /* of innerloop */
                 end /* of outerloop */

Inside the inner loop, at "more stuff", I will sometimes want to drop out
of the inner loop and go back to the outer loop.  An "iterate outerloop"
instruction would do exactly what I want.

Unfortunately, the iterate instruction works only if the do-loop has a
control variable, which a do-until does not.

Is there a way to do what I want?  Is there a better way of thinking about
the problem that doesn't require an iterate at all?  I don't think it
would be a good idea to use SIGNAL.

                         Jack Hamilton
                         jfh@cup.portal.com

patterso@hardees.rutgers.edu (Ross Patterson) (07/02/89)

Jack F Hamilton <jfh@cup.portal.com> writes:
>   outerloop: do until (a=1)
>                 /* stuff */
>   innerloop:    do until (b=2)
>                 /* more stuff */
>                    end /* of innerloop */
>                 end /* of outerloop */
>
>Inside the inner loop, at "more stuff", I will sometimes want to drop out
>of the inner loop and go back to the outer loop.  An "iterate outerloop"
>instruction would do exactly what I want.

Or a "leave innerloop".  You can have either, quite easily.   If  all you want
is to wind up after innerloop's end, you can just use "leave".   If you really
want to go back to the top of outerloop, you need to assign a control variable
to it, as in "do I=1 until (a=1)", and then "leave I"  will work.   Most folks
don't realize that both the increment and test clauses in a DO instruction are
optional in REXX.

>                                                     I don't think it
>would be a good idea to use SIGNAL.

That's correct, but for more than just asthetic reasons.  As  the REXX author,
Mike Cowlishaw, will tell you at any and all opportunities, SIGNAL isn't GOTO.
It's intended for ABNORMAL transfers of control, and that colors  its use very
heavily.  For example, it terminates all active  DO, IF,  INTERPRET and SELECT
instructions in the active routine (but not in any calling routines).   So you
can't use it to move from an inner to an outer loop.

Ross Patterson
Rutgers University