Skip to content

Instantly share code, notes, and snippets.

@iris-yeh

iris-yeh/lua.lua Secret

Created May 6, 2021 15:40
i = 0
-- while loop用法是 while (condition) do ... end
while true do
    i = i + 1
    print('i= ' .. i)
    
-- %是取餘數,如果是雙數的話,就直接從新進入迴圈(continue)
if i % 2 == 0 then
        print('continue')
-- 因為lua沒有continue的功能,所以通常大家都會用goto來模擬
goto continue
    elseif i == 3 then
        print('break')
-- 可以用break直接離開迴圈
break
    end
    print('end')
    ::continue::
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment