Lua - break statement

Published 2014/03/05 by Admin in LUA

The break statement is used to exit a loop.

a = 0

while true do

a = a+1

if a==10 then 

break

end

end

print(a)

Output:

10


Lua - for statement

Published 2014/03/03 by Admin in LUA

The for statement allows you to repeat the same task for a predefined amount of iterations.

 

Count from 1 to 4 in intervals of 1

for a=1,4 do io.write(a) end

print()

Output:

1234

 

Count from 1 to 6 in intervals of 3

for a=1,6,3 do io.write(a) end

print()

Output:

14

 

Sequential iteration form

for key,value in pairs({1,2,3,4}) do print(key,value) end

Output:

1     1

2     2

3     3

4     4



Lua - repeat until statement

Published 2014/03/03 by Admin in LUA

The repeat until statement allows you to perform a repetitive task until a certain condition is met.

a=0

repeat

a=a+1

print(a)

until a==5

Output:

1

2

3

4

5


Lua - while statement

Published 2014/03/03 by Admin in LUA

The while statement allows you to repeat a task until a certain condition is met.

a=1

--this is a comment

while a~= 5 do  -- Lua uses ~= to mean not equal 

a=a+1

io.write(a.." ")

end

Output:

2 3 4 5


my coding

This is a collection of all the coding gems I have found and would like to share with the world!