Re: GOTO

new topic     » goto parent     » topic index » view thread      » older message » newer message

Michael Nelson said:

> I have an idea for a restricted goto:
>
> 1. A label would be allowed only immediately before or immediately after a
> loop termination (end for or end while) statement.

Many years ago, the University of Waterloo implemented the UW_Tools, a
series of extensions to the Time Sharing Command Library for Bull's GCOS 8
operating system. Now under the care of Thinkage, Ltd., they still run on
some venerable DPS 9000's.

The UW_Tools included the EXEC command, a command file (read 'batch')
processor with its own internal language. EXEC included one of the strangest
implementations of GOTOs I've ever seen. Two main differences were apparent:

a) With a $*$REWIND [ ON | OFF ] statement you could control whether the
search for the label, if failed at EOF, would restart at the beginning of
the file. This let you build very interesting recursions, especially since
you could reset $*$REWIND any way and any place you chose.

b) You could add a $*$CATCH statement, which acted as a 'catch-all' label
for any $*$GOTO without a matching label. Very useful for debugging.

Goes without saying that this made for some of the strangest-looking code
I've ever seen or written, hardest to follow since APL.

> 2.  A label could be branched to only from within the loop, including
nested
> loops:
>
> for i=1 to 50 do
>      -- some statements
>     while 1 do
>         -- lots of statements
>         if x=1 then goto continue_while end if
>         if x=2 then goto continue_for end if
>         if x=3 then goto exit_while end if  -- could use exit here
>         if x=4 then goto exit_for end if
>         -- lots more statements
>         continue_while:
>     end while
>     exit_while:
>     -- more statements
>     continue_for:
>  end for
> exit_for:
> -- rest of program
>
> This would simplying nested loop coding while virtually eliminating
> potential abuse.  Note that only the case where x=3 is now doable without
> flag variables, etc.  I believe this is much more readable than flags.
>

This is actually useful in some cases. However, I would suggest using 'next'
and 'exit' statements instead of the 'goto / label' constructs. Still more
readable, less code and probably less overhead:

> for i=1 to 50 do
>      -- some statements
>     while 1 do
>         -- lots of statements
>         if x=1 then next while end if
>         if x=2 then next for end if
>         if x=3 then exit while end if
>         if x=4 then exit for end if
>         -- lots more statements
>     end while
>     -- more statements
>  end for
> -- rest of program

And maybe we could even bring back an updated version of Fortran's 'computed
goto':

goto (next while, next for, exit while, exit for), x

Sorry. I just couldn't resist adding to the confusion ...

Gerardo E. Brandariz


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu