Re: Goto, etc.

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

On Wed, 17 Nov 1999 08:07:44 +1100, Derek Parnell <dparnell at BIGPOND.NET.AU>
wrote:

>I've see this sort of thing before. However, it creates an opportunity for
>bugs to creep in, because if you ever change the nesting levels, you have
>to review every "exit" integer to make sure its still the right number.
>
>eg. Original Code...
>for i=1 to 10 do
>    for j=5 to 25 by 5 do
>        while k<75 do
>            if error1 then exit  end if -- or exit 1
>            if error2 then exit 2 end if
>            if error3 then exit 3 end if
>        end while
>    end for
>end for
>
>eg. Modified Code...
>for i=1 to 10 do
>  for z=1 to 3 do
>     ...
>    for j=5 to 25 by 5 do
>        while k<75 do
>            if error1 then exit 2 end if <<<Must Change
>            if error2 then exit 3 end if <<<Must Change
>            if error3 then exit 4 end if <<<Must Change
>        end while
>    end for
>  end for
>end for
>
>
>cheers,
>Derek Parnell
>Melbourne, Australia

Especially if the for is being more for control of code flow than for actual
looping. Same goes double for while statements. Whoever it was that came
up with the idea of using the the for  variable as the tag had the right
idea. No label needed and no confusion as to depth. I would go for the


  while[A] x > 0  do
     while[B] y > 0 do

etc., etc. with exit[A] and exit[B] as the exit side. Then, if you coded a
while with no subscript it could not be the target of a subscripted exit.
This would allow the programmer to prevent someone from skipping
through a given while level from below without specific logic at that while
level. The while subscript would follow all the rules of a for variable except
that it would have no content. That way, no one would have to declare all
their while subscripts just the way they don't have to declare there for
variables now. The subscript carries with it the idea of a sequence of
items, which it in fact would be. Just, a sequence that no one has direct
access to. If you wanted to give it a job, it could be an implicit loop
counter if declared as an integer that would cost very little. How many
times have you wanted a to get the current loop count, but didn't
want the code of the count to get in the way of your real code.

Everett L.(Rett) Williams
rett at gvtc.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu