[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Predefined labels (Inspired by discussion on: Why do we have ipairs?)
- From: "Joseph Manning" <manning@...>
- Date: Fri, 27 Jun 2014 17:08:21 +0100
On 2014-Jun-27 (Fri) at 05:15 (-0400), Sean Conner wrote:
>> If you are serious about this, you can remove "while", "repeat", "until",
>> "else", "break" and "for" and replace them all with just "if" and "goto".
>>
>> [ snip ]
Seán,
Modula-2 and Modula-3 have a powerful and flexible "LOOP" statement:
LOOP
<statements>
END
which repeatedly performs <statements> until explicitly terminated
by an EXIT statement.
Both "while" and "repeat" can be realised in the very obvious way
( now using lower-case keywords as in Lua, and "break" for "EXIT" ):
while <condition> do
<statements>
end
is now
loop
if not <condition> then break end
<statements>
end
and
repeat
<statements>
until <condition>
is now
loop
<statements>
if <condition> then break end
end
However, whereas "while" / "repeat" allow only a single <condition>,
and then only at the start / end of the iteration, "loop" allows any
number of <condition>s, which can occur anywhere in the iteration.
It's especially useful for "n-and-a-half" type iterations, such as
reading and processing items until a sentinel is reached, but not
processing the sentinel itself ( messy with "while" / "repeat" ).
Moreover, the whole problem with "continue" does not appear to arise
with the "loop" statement.
Yes, of course "loop" can be realised with "while true do", but the
latter form seems a bit ugly, to my eyes.
Joseph
------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / manning@cs.ucc.ie
------------------------------------------------------------------------