Keithley 2450 Reference Manual page 514

Interactive sourcemeter instrument
Table of Contents

Advertisement

Model 2450 Interactive SourceMeter® Instrument Reference Manual
Example: Generic for
days = {"Sunday",
"Monday",
"Wednesday",
"Friday",
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
Monday
Tuesday
Wednesday
Thursday
Friday
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
2450-901-01 Rev. B/September 2013
"Tuesday",
"Thursday",
"Saturday"}
1
Sunday
2
Monday
3
Tuesday
4
Wednesday
5
Thursday
6
Friday
7
Saturday
Section 7: Introduction to TSP operation
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
7-23

Advertisement

Table of Contents
loading

Table of Contents