Interactive SourceMeter® Instrument Reference Manual Section 7:
Introduction to TSP operation
2461-901-01 A/November 2015 7-23
Example: Generic for
"Monday", "Tuesday",
"Wednesday", "Thursday",
"Friday", "Saturday"}
for i, v in ipairs(days) do
print(days[i], i, v)
The generic
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
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")
This example defines a
value
(breakValue) so that the break statement is
used to exit the while
k reaches 0.
Output:
Going to break and k = 3