13: Introduction to TSP commands 2470 High Voltage SourceMeter Instrument
13-24 2470-901-01 Rev. A / May 2019
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 = element + 1
Count elements in list
using repeat:
1 One
2 Two
3 Three
4 Four
5 Five
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])
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