Control Structures

<< Click to Display Table of Contents >>

Navigation:  Multi-Protocol MasterOPC Server > Lua 5.1 Reference Manual > The Language and syntax > Statements >

Control Structures

Lua supports the only variant of a control construction, the if statement of conditional transfer (there are no statements like "case-switch").

The if statement has the following syntax:

if (expression) then

--code, which is executed if the expression is true

else

--code, which is executed if the expression is false

end

For example:

if (a==2) then

c=10

else

c=20

end

Note. Pay attention that the "not equal" operator is typed as '~=' in Lua.

A logical expression in control constructions can return any value. The values false and nil are considered as false. All other values (including 0 and empty string!) are considered as true.