![Keithley 707B Скачать руководство пользователя страница 217](http://html.mh-extra.com/html/keithley/707b/707b_reference-manual_661685217.webp)
Section 6: Instrument programming
Models 707B and 708B Switching Matrix Reference Manual
6-26
707B-901-01 Rev. A / August 2010
Example: While
Code
Notes and output
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 will exit when
list[element] = nil
.
Count list elements on
numeric index:
1.00000 One
2.00000 Two
3.00000 Three
4.00000 Four
5.00000 Five
6.00000 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
Example: Repeat until
Code Notes
and
output
list = {"One", "Two", "Three", "Four",
"Five", "Six"}
print("Count elements in list using repeat:")
element = 1
repeat
print(element, list[element])
element = e 1
until not list[element]
Count elements in list using
repeat:
1.00000 One
2.00000 Two
3.00000 Three
4.00000 Four
5.00000 Five
6.00000 Six
For loops
There are two variations of
for
statements supported in Lua: numeric and generic.
NOTE
In a
for
loop, the loop expressions are evaluated once, before the loop starts.