Module:Sandbox

From Wikiversity
Jump to navigation Jump to search

local p = {}
 
function p.forloop()
    local i
    local result
 
    result = ';for\n'
    for i = 2, 10, 2 do
        result = result .. ":i = " .. i .. '\n'
    end
 
    return result
end
 
function p.whileloop()
    local i
    local result
 
    result = ';while\n'
    i = 2
    while i <= 10 do 
        result = result .. ":i = " .. i .. '\n'
        i = i + 2
    end
 
    return result
end
 
function p.repeatloop()
    local i
    local result
 
    result = ';repeat\n'
    i = 2
    repeat 
        result = result .. ":i = " .. i .. '\n'
        i = i + 2
    until i > 10
 
    return result
end
 
return p