2-50 Return to Section Topics 2600S-901-01 Rev. C / January 2008
Section 2: TSP Programming Series 2600 System SourceMeter® Instruments Reference Manual
Branching
TSL uses the “if” keyword to do conditional branching.
--
-------------------------------- IF blocks ------------------------
--
if 0 then -- Zero IS true! This is a contrast to C where 0 evaluates
print("Zero is true!") false. In TSL, “nil” is false and everything else is true.
else
print("Zero is false.")
end -- if expression 1.
x = 1
y = 2
if (x and y) then
print("' if ' expression 2 was not false.")
end -- if expression 2.
if (x or y) then
print("' if ' expression 3 was not false.")
end -- if expression 3.
if (not x) then
print("' if ' expression 4 was not false.")
else
print("' if ' expression 4 was false.")
end -- if expression 4.
if x == 10 then
print("x = 10")
elseif y > 2 then
print("y > 2")
else
print("x is not equal to 10, and y is not less than 2.")
end -- if expression 5.
Output of code above:
Zero is true!
' if ' expression 2 was not false.
' if ' expression 3 was not false.