1. Loop
- Posted by Dan-Åke Engqvist <danake_engqvist at hotmail.com> Jun 01, 2007
- 600 views
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
2. Re: Loop
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Jun 01, 2007
- 564 views
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
3. Re: Loop
- Posted by Dan-Åke Engqvist <danake_engqvist at hotmail.com> Jun 02, 2007
- 573 views
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
4. Loop
- Posted by David Shane <DSDUDE1116 at AOL.COM> Sep 08, 1998
- 541 views
Is there any command to cause a program to loop over and over until control+c is pressed?
5. Re: Loop
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> Sep 08, 1998
- 539 views
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
6. Re: Loop
- Posted by Robert B Pilkington <bpilkington at JUNO.COM> Sep 08, 1998
- 593 views
- Last edited Sep 09, 1998
>>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]