print "Hello World!"
print(type("Hello world")) --> string
print(type(10.4*3)) --> number
print(type(print)) --> function
print(type(type)) --> function
print(type(true)) --> boolean
print(type(nil)) --> nil
print(type(type(X))) --> string
= operator assigns the value of the expression on the right to the variable on the left.
total = pennies * 0.01
total = count * 0.05 + total
Loop operator:if condition then operator // optional
else operator
Task: Input an integer number n and output the sum: 1+22+32+...+n2. Use input validation for n to be positive.while condition do operator end
n = io.read()
n = tonumber(n)
if (n > 0) then
sum = 0
i = 0
while
(i <= n)
do
sum = sum + (i * i)
i = i + 1
end
print(sum)
end
where:function name ( parameter1, parameter2, ...)
statements
end
// function definition
function addition (a, b)
r = a + b
return r
end
// invoking the function
z = addition (5,3);
print ("The result is " .. z);
name = {}
where:name[position];
//we declare the array and the variable for the loop
a = {}
i = 0
for i = 1, 10 do
a[i] = i*i
end