Learn

How do we use code to tell a computer this: “Create a variable and call a function 15 times”?

We could write it out 15 times:

create a variable call a function create a variable call a function create a variable call a function....

…We’ll spare you the rest. This approach takes a long time and it can easily lead to mistakes. Instead, let’s give the instructions once and tell the computer how many times to repeat them:

Repeat this 15 times: create a variable call a function

This structure is called a loop, and you’ll learn all about them in this lesson. These special structures in programming will give you the ability to repeat instructions multiple times without writing the instructions out multiple times.

This lesson will cover:

  • for loops
  • while loops
  • for each loops

By the way, we assume that you’re familiar with creating variables, using operators, calling functions, and working with lists.

Instructions

Create a pattern WITHOUT loops: In the text box, repeat these instructions 10 times, then run it:

  1. Place a pink tile
  2. Place a orange tile
  3. Place a mint tile

If you did it correctly, you’ll see all 30 tiles placed on the board!

Sign up to start coding

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?