This structure is useful for repeating a series of steps a number of times. It is most often used to loop around reading a table, but doesn't have to be.
A repeat step is always found with an end repeat step somewhere after it. The steps between those two commands are repeated the stated number of times:
The number of times the loop is set to repeat is set when the repeat command is encountered. You can use a variable name to set the number of repeating times, but changing the variable's value inside the loop does not change how many times the steps will be repeated:
In the above, the loop will be executed five times because the value was 5 when the 'repeat' was encountered. This differs from how while loops work: in those loops the condition is re-evaluated each time PsyScript goes around the loop.
repeat value times
…
end repeat
Makes PsyScript repeat the steps between the repeat and the end repeat a number of times. If the value is zero or a negative number, the steps inside the loop are skipped entirely. If the value is not a number, monkeys may fly out of your nose.
repeat 10 times
repeat $varPrimingAttempts times
repeat for each row in table tablename
…
end repeat
Makes PsyScript count the number of rows in the named table and repeat the steps between the repeat and the end repeat that many times. If there are no rows in that table, the steps inside the loop are skipped entirely.
repeat for each row in table soundStims