lua-users home
lua-l archive

Re: Why does this exit the function early?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


You were using "break" as if it were "continue", which lua doesn't have.
break terminates the while loop.
Paul Butler wrote:
Newbie question.....
Why does the "break" end the function?
I was expecting it to count to 10 and just skip over 5.
function doThis()
 local count = 0
 while true do
 count = count + 1
	if count == 5 then break end
	print(count)
	if count == 10 then return end
 end
 print("why are we here?")
end
doThis()

AltStyle によって変換されたページ (->オリジナル) /