[comp.sys.amiga.programmer] AREXX Question. How To Goto.

schur@isi.edu (Sean Schur) (01/21/91)

I would like to know what works as a "goto" statement in AREXX.
I noticed that you can "label" any point in the program with the
command - 

label:

But once you've labeled that point, how do you tell the program to
go to that point? Is this the way to do a "goto" or am I way off base?
If I am, I would appreciate it if someone could steer me in the
right direction.

Thanks.

=======================================================================
Sean Schur		    			USENET: schur@isi.edu	
Assistant Director Amiga/Media Lab		Compuserve: 70731,1102	
Character Animation Department			Plink: OSS259	
California Institute of the Arts
=======================================================================

graham@venus.iucf.indiana.edu (JIM GRAHAM) (01/21/91)

In article <16433@venera.isi.edu>, schur@isi.edu (Sean Schur) writes...
>I would like to know what works as a "goto" statement in AREXX.
>I noticed that you can "label" any point in the program with the
>command - 
> 
>label:
> 
>But once you've labeled that point, how do you tell the program to
>go to that point? Is this the way to do a "goto" or am I way off base?
>If I am, I would appreciate it if someone could steer me in the
>right direction.
> 
use the call statement.

Suppose you have a section labeled "goober:"

The way to "go" there is:

       call goober

At the end of the block labeled goober:
insert the statement "return".  This takes you back to the point from
which goober: was called.

For example:
--------------------------cut here-----------------------------------

/* Test script.  Tests call to a label and return from the label. */

say "You're here..."

call goober

say "You're back!"

exit

goober:

say "Howdy-doody, goober here!"

return
----------------------------------------------------------------------
It's that simple.

-Jim

-> ->Disclaimer: I'm not ashamed of what I say. <- <-
     Sorry if the above disclaimer is too long.
 ______________________________________________________________________
| Internet: graham@venus.iucf.indiana.edu                              |
| UUCP:     dolmen!graham@iuvax.cs.indiana.edu                         |
| FIDO:     Soon!                                                      |
| BBS:      The PORTAL DOLMEN BBS/ParaNet ALPHA-GAMMA (sm) (9:1012/13) |
|            (812) 334-0418, 24hrs.                                    |
|______________________________________________________________________|

stevem@hal.CSS.GOV (Steve Masters) (01/21/91)

graham@venus.iucf.indiana.edu (JIM GRAHAM) writes:

>In article <16433@venera.isi.edu>, schur@isi.edu (Sean Schur) writes...

>>I would like to know what works as a "goto" statement in AREXX.
>>I noticed that you can "label" any point in the program with the
>>command - 
>> 
>>label:
>> 
>>But once you've labeled that point, how do you tell the program to
>>go to that point? Is this the way to do a "goto" or am I way off base?
>>If I am, I would appreciate it if someone could steer me in the
>>right direction.

>use the call statement.

The 'call' statement is for subroutine (FORTRAN analogy) calls...enter and return
to the statement after the call.  The AREXX statement for 'goto' is 'signal'.

/* */
say '1'
signal thelabel
say '2'

thelabel:
say '3'
exit

The program above will print 1 then 3 (skipping the "say '2'" statement.  The
manual discourages the use of 'signal' as a 'goto' because it is not 'structured
programming.' (sigh :) ...before we start a style war...I agree it should rarely
be needed, but I have seen some real programs (tm) that could have been
greatly simplified in design and readability with a simple goto, signal, etc.)


Steve Masters   stevem@hal.CSS.GOV
ENSCO, Inc.
Melbourne, FL  32940
(407) 254 4122

dac@prolix.ccadfa.oz.au (Andrew Clayton) (01/21/91)

In article <16433@venera.isi.edu>, Sean Schur writes:

> I would like to know what works as a "goto" statement in AREXX.
> I noticed that you can "label" any point in the program with the
> command - 
> 
> label:
> 
> But once you've labeled that point, how do you tell the program to
> go to that point? Is this the way to do a "goto" or am I way off base?

CALL LABEL

Your routine should have a RETURN


e.g. 

/* Rexx */

Call Initialise

Say "Initialise Completed"

...

Initialise:

Say "Do magic things here"

Einstien = wrong
SowsEar = SilkPurse
Say "Time Flies Like an Arrow"
Say "Fruit Flies Like A Banana"

RETURN

/* end of Arexx */

Hope this helps.

Dac
(p.s. Goto's are considered 'bad')
 _l _  _   // Andrew Clayton. Canberra, Australia.         I Post  .
(_](_l(_ \X/  ccadfa.cc.adfa.oz.au!prolix!dac                     . .  I am.                   
-------- I cannot send or receive mail to or from sites outside of Australia.

andy@research.canon.oz.au (Andy Newman) (01/23/91)

Try ``signal''  e.g.

	signal fred


	...  code


fred:

	...  more code
-- 
Andrew Newman, Software Engineer.            | Net:   andy@research.canon.oz.au
Canon Information Systems Research Australia | Phone: +61 2 805 2914
P.O. Box 313 North Ryde, NSW, Australia 2113 | Fax:   +61 2 805 2929