Model 2461 Interactive SourceMeter® Instrument Reference Manual
Section 7: Introduction to TSP operation
2461-901-01 A/November 2015
7-21
While loops
To use conditional expressions to determine whether to execute or end a loop, you use
while
loops.
These loops are similar to
(on page 7-19) statements.
while
expression
do
block
end
Where:
•
expression
is Lua code that evaluates to either
true
or
false
•
block
consists of one or more Lua statements
The output you get from this example may vary depending on the data format settings of the
instrument.
Example: While
list = {
"One", "Two", "Three", "Four", "Five", "Six"}
print("Count list elements on numeric index:")
element = 1
while list[element] do
print(element, list[element])
element = e 1
end
This loop exits when
list[element]
= nil
.
Output:
Count list elements on
numeric index:
1 One
2 Two
3 Three
4 Four
5 Five
6 Six
Repeat until loops
To repeat a command, you use the
repeat
...
until
statement. The body of a
repeat
statement
always executes at least once. It stops repeating when the conditions of the
until
clause are met.
repeat
block
until
expression
Where:
•
block
consists of one or more Lua statements
•
expression
is Lua code that evaluates to either
true
or
false
The output you get from this example may vary depending on the data format settings of the
instrument.