Section 6: Instrument programming
Models 707B and 708B Switching Matrix Reference Manual
6-24
707B-901-01 Rev. A / August 2010
Conditional branching
Lua uses the
if
,
else
,
elseif
,
then
, and
end
keywords to do conditional branching.
Note that in Lua,
nil
and
false
are
false
and everything else is
true
. Zero is
true
in Lua.
The syntax of a conditional block is as follows:
if expression then
block
elseif expression then
block
else
block
end
Where:
•
expression
is Lua code that evaluates to either
true
or
false
•
block
consists of one or more Lua statements
Example: If
Code Output
if 0 then
print("Zero is true!")
else
print("Zero is false.")
end
Zero is true!
Example: Comparison
Code Output
x = 1
y = 2
if x and y then
print("Both x and y are true")
end
Both x and y are true
Example: If and else
Code Output
x = 2
if not x then
print("This is from the if block")
else
print("This is from the else block")
end
This is from the else block