cheat-sheet-lua/support/while.lua
2023-01-13 22:50:35 +01:00

41 lines
706 B
Lua

-- Jeb while loop
local jebSum = 0
print('jeb : '..jebSum)
while jebSum < 10 do
jebSum = jebSum + 1
print('jeb : '..jebSum)
end
print('\n')
-- Rob for loop
for i = 1, 10 do
print('Rob : '..i)
end
print('\n')
-- Tim for loop
for i = 0, 20, 2 do
print('Tim : '..i)
end
print('\n')
-- Clara for loop
for k,v in pairs({'hi', 'hello', 'smart', 'and', 'or', 'if', 'add', 'die', 'negatif', 'positive'}) do
print('Clara : '..k..' '..v)
end
print('\n')
-- Mart while loop
local martSum = 0
repeat
print('Mart : '..martSum)
martSum = martSum + 1
until martSum > 10
print('\n')
-- Breaking out loop
while true do
print('Breaking out in')
if true then break end
end
print('Breaking out -> Done')