[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: why no "continue" statement for loops?
- From: "Bilyk, Alex" <ABilyk@...>
- Date: Tue, 17 Jun 2003 17:22:21 -0700
Funny enough, it is easier to simulate "break" with "continue" then the other way around. Assuming there was no 'break' but 'continue' instead, one could do something like
local LOOP_BREAK = false
while (not LOOP_BREAK and <whatever>) do
LOOP_BREAK = true; continue; - this is the "break" statement
This looks pretty clean and easily readable.
From: Nick Trout [mailto:email@example.com]
Sent: Tuesday, June 17, 2003 12:48 PM
To: Lua list
Subject: RE: why no "continue" statement for loops?
> Every time I write a little program I end up wanting a continue
> statement for loops. Does this exist already or is there an
> that I've missed? If not then how to people not write ugly
> "if this then ... if that then ... if other then ... end end
> end" code to serve the same purpose of just jumping back to
> the top of the loop?
There's no switch statement either. You might emulate continue using
done = false
while not done do
local i = 1
while true do
if ... then
break -- continue
if ..some test... then
done = true
i = i+1 -- next iteration