RE: About GOTO (was RE: fixed windows)

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

On 7 Aug 2003 at 14:01, Tony Bucholtz wrote:

> 
> It seems to me that a conditional goto, designed only for loop control 
> and exiting, woould be much better than an unlimited "goto". Here's some 
> pseudocode that outlines my thinking:
> 
> for i = 1 to 10
>   -- imaginary "label A"
>   <some code here>
>   if <condition>
>      redo -- acts like goto label A - repeats this pass thru
>           -- the loop; index variable i doesn't change
>   end if
>   if <condition>
>      loop -- acts like goto label B - skips the remainder of
>           -- the code for this pass thru the loop
>   end if
>   if <condition>
>      exit -- acts like goto label C - get out of loop NOW!
>   end if
>   -- imaginary "label B"
> end for
> -- imaginary "label C"
> 
> The exit, redo and loop syntax would give us more control than the 
> simple existing "exit", without using the (apparently unpopular) goto.
> The idea could be extended to nested loops, e.g.:
> 
> for i = 1 to 10 
>   -- imaginary "label A"
>   for j = 1 to 10
>      -- imaginary "label B"
>      <code> 
>      if <condition>
>         redo -- goto label B
>      end if
>      if <condition>
>         redo i -- here's where it gets tricky: goto label A
>                -- note the use of the "outer loop" index to
>                -- identify where it is we're going
>      end if
>      if <condition>
>         loop -- goto label C - there's no index identifier, so
>              -- this "loop" is scoped to the containing j loop
>      end if
>      if <condition>
>         exit -- goto label D
>      end if
>      if <condition>
>         exit i -- goto label E
>      end if
>      -- imaginary label C
>   end for
>   -- imaginary label D
> end for 
> -- imaginary label E
> 
> This would also work for "while" loops, although identifying the "while" 
> loop in nested code may be problematic:
> 
> for i = 1 to 10
>    while 1 do
>       while 1 do
>          if <condition>
>             exit 1 -- huh?
>          end if
>       end while
>    end while
> end for
> 
Whats interesting in the above  is that comments are used to
document precisely what the control constructs do, and those
comments consist mostly of goto and label!
If goto and label explain the flow so well...
Disallowing goto jumping into loops prevents the development of
spaghetti.

Karl B.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu