1. continue statement
------=_NextPart_000_0010_01BFDB7D.BC098A40
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
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
example:
euphoria:
=20
while 1 do
if p then
k+=3D1
switch=3D1
end if
if switch=3D1 then --this has to be checked every time
...do actions
else
switch=3D0
end if
end while
-------------------------------------------------------------------------=
-------
with continue statement, like in c:
=20
while 1 do
if p then
k+=3D1
continue --goes to top of loop
end if
...do actions
end while
because of these things i sometimes think about going back to c, if only =
compilation time wasnt so long.
i like shortcuts in C
------=_NextPart_000_0010_01BFDB7D.BC098A40
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-2" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3401" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>euphoria should have continue statement =
like in c=20
to be used in while/for loops.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>with continue statement you go to =
beginning of loop=20
when you dont want statements after continue to be =
executed.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>in euphoria now you must define switch, =
and have to=20
check it every time in loop, which slows it down</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>example:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>euphoria:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>while 1 do</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>if p then</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> k+=3D1</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
switch=3D1</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>end if</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>if switch=3D1 then --this has to be =
checked every=20
time</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> ...do =
actions</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>else</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> =
switch=3D0</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>end if</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>end while</FONT></DIV>
<DIV> </DIV>
<DIV>
<HR>
</DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>with continue statement, like in =
c:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>while 1 do</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>if p then</FONT></DIV>
<DIV> k+=3D1</DIV>
<DIV><FONT face=3DArial size=3D2> continue --goes to =
top of=20
loop</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>end if</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>...do actions</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>end while</FONT></DIV>
<DIV> </DIV>
<DIV>because of these things i sometimes think about going back to c, if =
only=20
compilation time wasnt so long.</DIV>
------=_NextPart_000_0010_01BFDB7D.BC098A40--
2. Re: continue statement
On Wed, 21 Jun 2000 12:39:26 +0200, <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
>
>example:
>euphoria:
>
>while 1 do
>if p then
> k+=1
> switch=1
>end if
>
>if switch=1 then --this has to be checked every time
> ...do actions
>else
> switch=0
>end if
>end while
I'm not sure I follow the above example. Can switch be something other
than 1 or 0? If p is non-zero, switch is set to 1 so we 'do actions'. If
p is zero then switch *might not* be equal to 1 so we set it to zero. (If
p is zero and switch is zero, then we are stuck in a loop that keeps
setting switch to zero... that part doesn't make sense.)
But I do follow what you are saying in the example below. On the other
hand, couldn't you accomplish the same thing by doing something like:
while 1 do
if p then
k += 1
else
...do actions
end if
end while
Am I missing something obvious here?
Brian
>--------------------------------------------------------------------------
>
>
>with continue statement, like in c:
>
>while 1 do
>if p then
> k+=1
> continue --goes to top of loop
>end if
>
>...do actions
>end while
3. Re: continue statement
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
4. Re: continue statement
On Thu, 22 Jun 2000 05:18:50 -0400, Derek Parnell wrote:
>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.
I think you'd have to come up with something more complex to convince me
that this is really useful. I think the following loop does the same thing
and I don't think it's any more or less confusing than haveing a 'next'
or 'continue':
while 1 do
if action0() then exit end if
if P then
if Q then
action1()
if not R then
action4()
action3()
end if
else
action2()
end if
end if
end while
-- Brian
-- ( playing the role of a skeptic; and I'm sure somebody will come up with
an example that will either convince me or will be so complex that I won't
want to try rewriting it. 8^)
5. Re: continue statement
On Thu, 22 Jun 2000 13:51:03 -0400, I wrote:
>while 1 do
> if action0() then exit end if
> if P then
> if Q then
> action1()
> if not R then
> action4()
> action3()
> end if
> else
> action2()
> end if
> end if
>end while
Ooops... make that:
while 1 do
if action0() then exit end if
if P then
if Q then
action1()
if not R then
action4()
action3()
end if
else
action2()
end if
else
action3()
end if
end while
-- Brian
-- (starting to see it's usefullness, mostly to avoid redundancy)
6. Re: continue statement
Geez, I still have an error in my conversion. So I've convinced myself and
I'll shut up now...
-- Brian
7. Re: continue statement
Brian Broker wrote:
> I think you'd have to come up with
> something more complex to convince me
> that this is really useful.
I've had quite a few situations where a continue would be nice. It can be
emulated, but that results in a loss of code clarity. It's been on my wish
list for some time.
-- David Cuny
8. Re: continue statement
On 22 Jun 2000, at 11:03, Cuny, David@DSS wrote:
> Brian Broker wrote:
>
> > I think you'd have to come up with
> > something more complex to convince me
> > that this is really useful.
>
> I've had quite a few situations where a continue would be nice. It can be
> emulated, but that results in a loss of code clarity. It's been on my wish
> list for some time.
I still say a goto command would cure that. It's an intrinsic "exit loop",
"bypass
codeblock", "terminate process", etc.. And since it will be in the C code
generated by
the Eu-compiler, i still see no reason to not have a goto in the Eu interpreted
code
language.
Kat