
Section 7: Introduction to TSP operation
Model 2461 Interactive SourceMeter® Instrument Reference Manual
7-22
2461-901-01 A/November 2015
Example: Repeat until
list = {"One", "Two", "Three", "Four", "Five", "Six"}
print("Count elements in list using repeat:")
element = 1
repeat
print(element, list[element])
element = e 1
until not list[element]
Output:
Count elements in list
using repeat:
1 One
2 Two
3 Three
4 Four
5 Five
6 Six
For loops
There are two variations of
for
statements supported in Lua: Numeric and generic.
In a
for
loop, the loop expressions are evaluated once, before the loop starts.
The output you get from these examples may vary depending on the data format settings of the
instrument.
Example: Numeric for
list = {"One", "Two", "Three", "Four", "Five", "Six"}
---------- For loop -----------
print("Counting from one to three:")
for element = 1, 3 do
print(element, list[element])
end
print("Counting from one to four, in steps of two:")
for element = 1, 4, 2 do
print(element, list[element])
end
The numeric
for
loop repeats a block of code while a control variable runs through an
arithmetic progression.
Output:
Counting from one to three:
1 One
2 Two
3 Three
Counting from one to four, in steps of two:
1 One
3 Three