Imagine we have a list of addresses to which we want to deliver mail. We would want the driver to go to each address in the list and drop off the package.

To go through that list of addresses, we would use a for-each loop. A for-each loop is a simple way to write code that works on each item in a list! We might program the delivery with code that looks like:

addresses = {"1 First St", "45 Eighth St", "90 Seventh St"}; for (each address in addresses) { Drive to the address Deliver package for that address }

This code will have the driver deliver the packages in the order of the list.

Use for-each loops in your programs to work on each item in a list!


In this exercise, we want each of our Codey’s to go to the goal. Place a loop for each Codey to follow inside of the for each loop.


Place a for or a while loop inside of the for each loop. Inside of the inner loop, Codey should move to the right.

For each Codey While Codey has not reached goal Move right

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?