Re: continue statement

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

On Wed, 21 Jun 2000 12:39:26 +0200, =?iso-8859-2?B?qWtvZGE=?=
<tone.skoda at SIOL.NET> wrote:

>euphoria should have continue statement like in c to be used in while/for
loops.
>
>with continue statement you go to beginning of loop when you dont want
statements after continue to be executed.
>in euphoria now you must define switch, and have to check it every time in
loop, which slows it down
>

I too would like this shortcut in the interpreter. I have asked for this
sort of thing before(back in November from memory). I know its a
disguised "goto" and can thus cause subtle bugs, but it can help make
otherwise deeply nested ifs more readable - which is one of the purposes of
source code. Thanks RDS for providing the "exit" statement, which is a
similar type of construct.

An example...

---
integer NextIter
constant DoWork = 0
constant SkipWork = 1
while 1 do
  NextIter = DoWork -- Reset flag.

  if action0() then exit end if
  if P then
    if Q then
      action1()
      if R then
        NextIter = SkipWork -- Set flag to skip further processing.
      end if
    else
      action2()
      NextIter = SkipWork -- Set flag to skip further processing.
    end if

    if NextIter = DoWork then -- If okay, do more processing
      action4()
    end if
  end if

  if NextIter = DoWork then -- If okay, do more processing
    action3()
  end if
end while


--- However with a "continue" or "next" statement...

while 1 do
  if action0() then exit end if
  if P then
    if Q then
      action1()
      if R then
        next -- Start next iteration
      end if
    else
      action2()
      next -- Start next iteration
    end if

    action4()
  end if

  action3()
end while

--- Of course, this is a simple example but in the real world, they can get
a lot more verbose.

-------
Cheers,
Derek

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

Search



Quick Links

User menu

Not signed in.

Misc Menu