1. Suggestion for conditional loops
- Posted by "Juergen Luethje" <j.lue at gmx.de> Jul 15, 2005
- 477 views
Hi all, I'd like to suggest a new syntax for conditional loops: Use "loop" or something similar (rather than "end while") to denote the end of a conditional loop, also allow conditional loops without a while statement. So the basic conditional loop would look like: do <command_1> <command_2> ... loop rather than currently while 1 do <command_1> <command_2> ... end while Then allow a while statement at the beginning *or at the end* of the loop: while x < 2 do <command_1> <command_2> ... loop do <command_1> <command_2> ... loop while x < 2 The advantage is in the last case, where we currently have to write: while 1 do <command_1> <command_2> ... if x >= 2 then exit end if end while The problems concerning compatibility are little, we just would have to replace "end while" with "loop" in existing programs. But I don't know whether this would require big changes in the parser. Also, we now always have "end <keyword>" (end if, end for, end function, ...). Using "do/loop" instead of "while/end while" would introduce an exception, so I don't know whether this actually ia good idea. But at least I wanted to tell you for discussion. Regards, Juergen -- Have you read a good program lately?
2. Re: Suggestion for conditional loops
- Posted by Jason Gade <jaygade at yahoo.com> Jul 15, 2005
- 472 views
Juergen Luethje wrote: > > Hi all, > > I'd like to suggest a new syntax for conditional loops: > > Use "loop" or something similar (rather than "end while") to denote the > end of a conditional loop, also allow conditional loops without a while > statement. So the basic conditional loop would look like: > do > <command_1> > <command_2> > ... > loop > > rather than currently > while 1 do > <command_1> > <command_2> > ... > end while > > > Then allow a while statement at the beginning *or at the end* of the > loop: > while x < 2 do > <command_1> > <command_2> > ... > loop > > > do > <command_1> > <command_2> > ... > loop while x < 2 > > > The advantage is in the last case, where we currently have to write: > while 1 do > <command_1> > <command_2> > ... > if x >= 2 then > exit > end if > end while > > > The problems concerning compatibility are little, we just would have to > replace "end while" with "loop" in existing programs. > > But I don't know whether this would require big changes in the parser. > Also, we now always have "end <keyword>" (end if, end for, end function, ...). > Using "do/loop" instead of "while/end while" would introduce an > exception, so I don't know whether this actually ia good idea. But at > least I wanted to tell you for discussion. > > Regards, > Juergen > > -- > Have you read a good program lately? > > Yes, Euphoria could use a loop with the test at the end so that it runs at least once. But I don't think it will be implemented. One way of doing it currently instead of using exit is:
-- example from wc.ex ch = getc(FILE) while ch != EOF do -- some logic to count lines, words, chars ch = getc(FILE) end while
The problem of course is that if you make any changes to the variable expression, you have two lines to change instead of one. C'est la vie with Euphoria. </eucode> {{{ ===================================== Too many freaks, not enough circuses. j.
3. Re: Suggestion for conditional loops
- Posted by "Kat" <gertie at visionsix.com> Jul 15, 2005
- 454 views
On 15 Jul 2005, at 11:59, Juergen Luethje wrote: > > > Hi all, > > I'd like to suggest a new syntax for conditional loops: > > Use "loop" or something similar (rather than "end while") to denote the > end of a conditional loop, also allow conditional loops without a while > statement. So the basic conditional loop would look like: > do > <command_1> > <command_2> > ... > loop Didn't we call those "repeat-until" loops? Been asked for, RobC said no. Kat > rather than currently > while 1 do > <command_1> > <command_2> > ... > end while > > > Then allow a while statement at the beginning *or at the end* of the > loop: > while x < 2 do > <command_1> > <command_2> > ... > loop > > > do > <command_1> > <command_2> > ... > loop while x < 2 > > > The advantage is in the last case, where we currently have to write: > while 1 do > <command_1> > <command_2> > ... > if x >= 2 then > exit > end if > end while > > > The problems concerning compatibility are little, we just would have to > replace "end while" with "loop" in existing programs. > > But I don't know whether this would require big changes in the parser. > Also, we now always have "end <keyword>" (end if, end for, end function, ...). > Using "do/loop" instead of "while/end while" would introduce an exception, so > I > don't know whether this actually ia good idea. But at least I wanted to tell > you > for discussion. > > Regards, > Juergen > > -- > Have you read a good program lately? > > > >