Repeat Loops
One of the great strengths of computers is their ability to perform repetitive tasks with ease. SenseTalk provides several different types of repeat loops for this purpose.
A repeat
loop is used any time you want to execute one or more statements repeatedly some number of times. The statements to be repeated are preceded by one of the repeat
statements described below, and must always be followed by an end repeat
statement to mark the end of the loop. Repeat loops may be nested.
Repeat Forever
Behavior: This form of repeat loop repeats indefinitely until terminated. Usually, you do not really want your script to keep looping forever (a condition known by programmers as an “infinite loop”), so repeat forever
loops typically include at least one exit
, return
, or pass
statement that breaks out of the loop when some condition has been met: The word forever
is optional.
Syntax:
repeat {forever}
statementList
end repeat
Example:
repeat forever
get nextValue(partList)
if it is empty then exit repeat // Generally there will be some handling within a forever repeat loop that provides a way to exit the repeat loop
TypeText it
end repeat