[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "continue" construct in Lua loops
- From: Thomas Hafner <thomas@...>
- Date: 22 Dec 2006 13:41:05 +0100
"Leo Razoumov" <slonik.az@gmail.com> wrote/schrieb <ee2a733e0612210507j15395dffnc602830c4c1a0b1@mail.gmail.com>:
> for i=0,9 do
> repeat
> if i>=3 and i<=7 then break end --exclude i= 3,4,5,6,7
> print(i)
> until true
> end
>
> Is there a more elegant way?
function foo (start)
for i=start,9 do
if i>=3 and i<=7 then return foo(i + 1) end --exclude i= 3,4,5,6,7
print(i)
end
end
foo(0)
Hmm, this solution is one line longer than yours. But if your code
example is just a snippet out of an already existing function, it may
have the same amount of lines in total.
Regards
Thomas