Repeat a sound four times a measure.

Computers are good at repetitive tasks: they exactly follow instructions and perform them quickly. But if the programmer has to write the same instructions for every repetition, they waste time and increase the chances of a mistake.

In our example, instead of literally writing “play a sound, play a sound, play a sound, play a sound”, programmers can use a loop structure. A loop is a sequence of instructions which is specified once but which may be carried out several times in a row. In this case there is one instruction (play a sound) and it should be carried out 4 times.

Loop structures can also specify that the instructions are repeated until a certain condition is met. For example, “Repeat a sound until you are booed off stage”.


Click the shapes in the diagram to move through each step of the loop structure.

What is the condition or count that must be met to stop looping?

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?