![Tektronix Keithley SourceMeter 2470 Reference Manual Download Page 611](http://html1.mh-extra.com/html/tektronix/keithley-sourcemeter-2470/keithley-sourcemeter-2470_reference-manual_1078034611.webp)
2470 High Voltage SourceMeter Instrument Reference Manual
Section 13: Introduction to TSP commands
2470-901-01 Rev. A /
May
2019
13-25
Example: Generic for
days = {"Sunday",
"Monday", "Tuesday",
"Wednesday", "Thursday",
"Friday", "Saturday"}
for i, v in ipairs(days) do
print(days[i], i, v)
end
The generic
for
statement works by using functions called iterators. On each iteration, the
iterator function is called to produce a new value, stopping when this new value is nil.
Output:
Sunday 1 Sunday
Monday 2 Monday
Tuesday 3 Tuesday
Wednesday 4 Wednesday
Thursday 5 Thursday
Friday 6 Friday
Saturday 7 Saturday
Break
The
break
statement can be used to terminate the execution of a
while
,
repeat
, or
for
loop,
skipping to the next statement after the loop. A break ends the innermost enclosing loop.
Return and break statements can only be written as the last statement of a block. If it is necessary to
return or break in the middle of a block, an explicit inner block can be used.
The output you get from these examples may vary depending on the data format settings of the
instrument.
Example: Break with while statement
local numTable = {5, 4, 3, 2, 1}
local k = table.getn(numTable)
local breakValue = 3
while k > 0 do
if numTable[k] == breakValue then
print("Going to break and k = ", k)
break
end
k = k - 1
end
if k == 0 then
print("Break value not found")
end
This example defines a
break
value
(
breakValue
) so that the
break
statement is
used to exit the
while
loop before the value of
k reaches
0
.
Output:
Going to break and k = 3