# Creating A Loop

Script [13.1.1]:

repeat 2 times
say "This is a loop"
end repeat


Explanation: Loops can be created using the repeat command. Here I have created a loop which will run 2 times. And within the repeat block, I have specified the commands to be executed.

As per the above Script, the statement “This is a loop” will be spoken twice.

Script [13.1.2]:

set i to 2
repeat i times
-- commands to be repeated
end repeat


Explanation: Loops can be created using variables too. Here I have assigned variable i to 2 and I have asked repeat block to repeat i times. I chose variable i, because in programming languages, we usually use i in loops.