4.3.1 - if then else
An if statement tests its condition
and executes its then-part or its else-part
accordingly.
The else-part is optional.
if a<0 then a = 0 end
if a<b then return a else return b end
if line > MAXLINES then
showpage()
line = 0
end
When you write nested ifs,
you can use elseif.
It is similar to an else followed by an if,
but it avoids the need for multiple ends:
if op == "+" then
r = a + b
elseif op == "-" then
r = a - b
elseif op == "*" then
r = a*b
elseif op == "/" then
r = a/b
else
error("invalid operation")
end
Copyright © 2003-2004 Roberto Ierusalimschy. All rights reserved.
|
|
 |