EasyManua.ls Logo

Keithley 2657A

Keithley 2657A
805 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Section 6: Instrument programming Model 2657A High Power System SourceMeter® Instrument Reference Manual
6-22 2657A-901-01 Rev. B/December 2012
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.
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])
end
The numeric for loop repeats a block of code while a control variable runs through an
arithmetic progression.
Output:
Counting from one to three:
1.00000e+00 One
2.00000e+00 Two
3.00000e+00 Three
Counting from one to four, in steps of two:
1.00000e+00 One
3.00000e+00 Three
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.00000e+00 Sunday
Monday 2.00000e+00 Monday
Tuesday 3.00000e+00 Tuesday
Wednesday 4.00000e+00 Wednesday
Thursday 5.00000e+00 Thursday
Friday 6.00000e+00 Friday
Saturday 7.00000e+00 Saturday
NOTE

Table of Contents

Related product manuals