General+Loops

Loops - Doing Something More Than Once

Loops allow you to program a sprite to do something more than once.

It is unlikely you would ever use the 'Forever' loop. This would make a sprite do something over and over again and never stop no matter what. This is not something we often need to do in programming! However, there are lots of ways we can get a program to do something more than once:



The following two types of loop are very useful.

The 'Repeat loop lets us decide how many time something will happen. It is also called a fixed loop. We enter the number of times we want the loop to repeat the instruction. It will never happen more or less than the number we enter. In the example above, whatever we put inside the yellow brackets will happen 10 times.



The 'repeat until' loop is also very common in programming. The instructions inside the loop will keep happening until a condition is true or false. For example, we might ask for someone for their password and we would want to keep asking for their password until they input the correct one.



Please see the next two pages for more information and examples of fixed and conditional loops.

The video below shows a Scratch sprite dancing using loops:

media type="custom" key="23970946" align="center"