Skip to content

Repeat an action

Use repeat to run code an exact number of times instead of writing it out manually.

whenGreenFlag(() => {
repeat(5, () => {
changeX(20);
wait(0.1);
});
});

This moves the sprite 20 steps to the right, five times in a row, with a short pause between each step β€” producing a stepping effect across the stage.

  • whenGreenFlag β€” run code when the green flag is clicked
  • repeat β€” run a block of code a fixed number of times
  • changeX β€” move along the x axis
  • wait β€” pause the script for a number of seconds
All recipes