In other languages

Help the wiki!

The Scratch Wiki is made by and for Scratchers. Do you want to contribute?

Learn more about joining as an editor!

See discussions in the Community Portal

Repeat () (block)

Repeat ()
2.0 Repeat ().png
Category Control
Type C

The Repeat () block is a Control block and a C block. Blocks held inside this block will loop a given amount of times, before allowing the script to continue.

If a decimal is put in, the number is rounded up.

This block has a slight delay, so for optimum speed of execution, single frame block stacks should be used.

Example Uses

As this block loops pieces of code, it is widely used for saving space and time. Some common uses are:

  • Repeating code — using the Repeat () block (and the Repeat Until () block) can save a lot of scripting.
repeat (10)
 change [variable v] by (1)
 next costume
 if <touching [Wall v]?> then
  clear
  broadcast [Reload v]
 else
  stamp
 end
  • Animation — rather than coding each costume change and delay individually, the Repeat () block (with the Next Costume block) can be used. This saves a lot of scripting.
repeat (8)
 wait (0.05) secs
 next costume
  • Continuous checks — a sprite can continuously move and sense, for example.
repeat (20)
 change y by (3)
 if <touching [edge v]?> then
  change [color v] effect by (75)

Workaround

Main article: List of Block Workarounds

This block can be replicated with the following code:

set [counter v] to (0)
repeat until <(counter) = (number of times)>
 . . .
 change [counter v] by (1)

See Also

  • This page was last modified on 30 August 2014, at 17:36.