[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: why no "continue" statement for loops?
- From: Supratik Champati <champati@...>
- Date: Tue, 8 Jul 2003 15:35:02 -0400
Is there a similar continue patch for lua 4.1 ?
-----Original Message-----
From: lb@get.it.pl [mailto:lb@get.it.pl]
Sent: Tuesday, June 17, 2003 5:23 PM
To: Lua list
Subject: Re: why no "continue" statement for loops?
JL> Every time I write a little program I end up wanting a continue
JL> statement for loops. Does this exist already or is there an alternative
JL> that I've missed? If not then how to people not write ugly
JL> "if this then ... if that then ... if other then ... end end end"
JL> code to serve the same purpose of just jumping back to the top of the
loop?
Adding `continue' statement to Lua is quite simple. The attached file
contains modified Lua 5 files: lex.h, lex.c and lparser.c. Test code
is as follows (also in attached file):
--
-- `continue' statement test
--
i = 0
while i < 7 do
i = i + 1
if i == 3 then continue end
if i == 6 then break end
io.write(i)
end
io.write(" ")
i = 0
repeat
i = i + 1
if i == 3 then continue end
io.write(i)
until i == 5
io.write(" ")
for i = 1, 5 do
if i == 3 then continue end
io.write(i)
end
print()
print(loadstring("if 2 > 1 then continue end"))
print(loadstring("do continue end"))
--
-- the result is:
--
-- 1245 1245 1245
-- nil [string "if 2 > 1 then continue end"]:1: no loop to continue near
`end'
-- nil [string "do continue end"]:1: no loop to continue near `end'
Enjoy!
Leszek Buczkowski