繰り返しループ
コンピュータの大きな強みの一つは、繰り返しタスクを容易に実行する能力です。この目的のために、SenseTalkはいくつかの異なる種類の繰り返しループを提供します。
repeat
ループは、一つ以上のステートメントを何回か繰り返し実行したいときに使用されます。繰り返すステートメントは以下に述べるrepeat
ステートメントの一つによって前置され、常にループの終了を示すend repeat
ステートメントによって後置される必要があります。繰り返しループはネストすることができます。
Repeat Forever
動作: この形式の繰り返しループは、終了するまで無限に繰り返します。通常、あなたはスクリプトが永遠にループし続けること(プログラマーにとっては「無限ループ」として知られている状態)を本当に望んでいませんので、repeat forever
ループは通常、少なくとも一つのexit
、return
、またはpass
ステートメントを含み、何らかの条件が満たされたときにループから抜け出します。forever
という単語はオプションです。
構文:
repeat {forever}
statementList
end repeat
例:
repeat forever
get nextValue(partList)
if it is empty then exit repeat // 一般的には、永遠に繰り返すループの中には、繰り返しループを終了する方法を提供する何らかのハンドリングが存在します。
TypeText it
end repeat
Repeat Number Times または For Duration
動作: この形式は、number
の表現によって指定された回数、またはduration
によって指定された時間の量のために繰り返します。
構文:
repeat {for} number {times}
statementList
end repeatrepeat {for} duration
statementList
end repeat
例:
repeat 6 times
click "Arrow"
end repeat
例:
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
動作: この形式の繰り返しループは、条件式がtrue
の値に評価されるまで、または指定された日時が到来するまで実行されます。条件または時間の式は、ループの最初とその後の各実行前に評価されます。
構文:
repeat until condition
statementList
end repeatrepeat until timeExpression
statementList
end repeat
例:
repeat until list is empty
put the last item of list
delete the last item of list
end repeat
例:
on ScrollUntilFound ImageName, myTime
Repeat until imagefound(image:imageName,waitfor:mytime)
if the counter is greater than 10 // Read more about the counter below
throw "image not found", imageName&&"not found when scrolling."
end if
Typetext PageDown
Wait 1
end repeat
end ScrollUntilFound
例:
repeat until "3:17 pm" // Repeats until the local system (eggPlant machine) clock hits 3:17 pm"
log "counting the seconds"
wait 1
end repeat
end repeat
end repeat
文法:
repeat at least once until condition
statementList
end repeat
例:
set CountDown to 1000
repeat while CountDown is greater than 500
put readtext("TimerTL","TimerLR") into CountDown // Uses OCR to read a dynamic value off the SUT's screen
wait 3
end repeat