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
Repeat Number Times or For Duration
Behavior: This form repeats the number of times specified by the expression number or for the amount of time specified by the duration.
Syntax:
repeat {for} number {times}
statementList
end repeatrepeat {for} duration
statementList
end repeat
Example:
repeat 6 times
click "Arrow"
end repeat
Example:
repeat 1 minute
If imagefound(imageName:"Notification", waitFor:0) then
Logwarning "The warning is still present."
wait 2
else
Log "The warning is gone."
Exit Repeat
end if
end repeat
Repeat Until Condition, Repeat Until Time
Behavior: This form of repeat loop executes until the condition expression evaluates to a value of true, or until a given date/time arrives. The condition or time expression is evaluated before the first and each subsequent execution of the loop.
Syntax:
repeat until condition