1. Loop

I would like to suggest that Euphoria should have loop-end loop.
It looks more clear and possibly runs a little faster
(since it doesn't has to check if 1 is true or not).

Instead of:
while 1 do
	do_something
	if something_is_true then exit end if
end while

It should be this:
loop
	do_something
	if something_is_true then exit end if
end loop

Dan-Åke Engqvist

new topic     » topic index » view message » categorize

2. Re: Loop

Dan-Åke Engqvist wrote:
> 
> I would like to suggest that Euphoria should have loop-end loop.
> It looks more clear and possibly runs a little faster
> (since it doesn't has to check if 1 is true or not).
> 
> Instead of:
> while 1 do
> 	do_something
> 	if something_is_true then exit end if
> end while
> 
> It should be this:
> loop
> 	do_something
> 	if something_is_true then exit end if
> end loop
> 
> Dan-Åke Engqvist

This optimisation is already being performed.

If you look at the emit.e file in the source directory, you'll see that,
when the conditional clause of a while statement is a nonzero constant,
the code which checks the condition on each loop iteration is not generated,
hence is not executed. This optimisation is mentioned in the release notes.

As to whether "while 1 do" is clearer than "loop"... The latter is shorter,
so it is better. This is typically the sort of things a preprocessor would do,
but there is no official preprocessor for Eu. There are a few in the archive.

CChris

new topic     » goto parent     » topic index » view message » categorize

3. Re: Loop

CChris wrote:
> 
> Dan-Åke Engqvist wrote:
> > 
...
> 
> This optimisation is already being performed.
> 
> If you look at the emit.e file in the source directory, you'll see that,
> when the conditional clause of a while statement is a nonzero constant,
> the code which checks the condition on each loop iteration is not generated,
> hence is not executed. This optimisation is mentioned in the release notes.

That's good
 
> As to whether "while 1 do" is clearer than "loop"... The latter is shorter,
> so it is better. This is typically the sort of things a preprocessor would do,
> but there is no official preprocessor for Eu. There are a few in the archive.
> 
> CChris

"loop" is better, but not because it is shorter. It just tell the program what
to do. "while 1 do" tell the program to do something if something that always
is true is true.

Now another loop: for-end for

for s={i1,j1,...} to {i2,j2,...} by {k1,k2,...}
    ...
end for

Would this be a good idea as an alternative to nested loops?

/Dan-Åke Engqvist

new topic     » goto parent     » topic index » view message » categorize

4. Loop

Is there any command to cause a program to loop over and over until control+c
is pressed?

new topic     » goto parent     » topic index » view message » categorize

5. Re: Loop

Hello,

>Is there any command to cause a program to loop over and over until
control+c
>is pressed?

I believe that putting the whole prog in this loop should do the trick:

integer k
while 1 do
-- program code or main procedure
k = get_key()
end while

I think that ctrl+C will exit any Euph prog while it is looking for
keyboard input.  At least ctrl+break should work.  There may even be a
simpler way to do this but I can't test it on my mailer.

Lewis Townsend


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

new topic     » goto parent     » topic index » view message » categorize

6. Re: Loop

>>Is there any command to cause a program to loop over and over until
>control+c
>>is pressed?
>
>I believe that putting the whole prog in this loop should do the
>trick:
>
>integer k
>while 1 do
>-- program code or main procedure
>k = get_key()
>end while
>
>I think that ctrl+C will exit any Euph prog while it is looking for
>keyboard input.  At least ctrl+break should work.  There may even be a
>simpler way to do this but I can't test it on my mailer.


Try this (untested) code:


include machine.e  -- allow_break()

allow_break(0)     -- CTRL-BREAK won't cause program to up and,
                   -- for all intents and purposes, crash.
integer key
while 1 do
    key = get_key()       -- Get input
    if check_break() then -- CTRL-BREAK or CTRL-C found
        exit              -- Exit loop
    end if
end while
-- Exit gracefully here (restore video mode, close files, etc)


_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu