Re: Euphoria features

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

Everett Williams wrote:

> Did I miss something...exit can accomplish this one.

Yes, the example was trivial.

I'd like to make my position on GOTOs more clear: I'm not really interested
in adding a GOTO to Euphoria. Rather, I'm more interested in a good way of
getting out of deeply nested logic structures in an efficient manner.

Using flags is the 'correct' way of doing it, but the resulting code often
seems to obscure the intent, rather than clarify it. Moving the block into a
routine is possible, but sharing variables can be problematic in Euphoria,
especially since they are scoped as local.

I seem to recall that even the K&R text acknowleged that the GOTO is the
best method of expressing that intent.

The 'problem' with block structures is that they are local; they neither
know about the blocks outside of themselves, or inside of them. If we were
only talking about 'for' loops, than something like:

   for i = 1 to 10 do
      for j = 1 to 10 do
         ...
         leave i loop
         ...
      end for
   end for

Would work. But there are 'while' loops as well. I suppose you could add
labels to the loops, as in:

   outerWhile: while true do
      for i = 1 to 10 do
         ...
         leave outerWhile:
         ...
      end for
   end while

This strikes me as being less clear than the pure GOTO, and it disallows
instance where you have a series of instructions, but want to stop if an
error is encountered:

   if handle = -1 then
      goto fileError:
   end if

   ...
   if writeResult = -1 then
      goto fileError:
   end if

   ...
   if closeFileResult = -1 then
      goto fileError:

   ...
   return

   fileError:
   ...
   return


Yes, I know that you could set a flag, etc. But it still seems to me that
the GOTO best expresses the intent of the code: if an error is encountered,
skip the rest of the code and run the error handler.

-- David Cuny

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

Search



Quick Links

User menu

Not signed in.

Misc Menu