FAQ: Loops - For Loops

This community-built FAQ covers the “For Loops” exercise from the lesson “Loops”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn How to Code

FAQs on the exercise For Loops

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

When I chose at the exercise, Loop for 20 times (meaning 20x3=60 tiles), I actually expected that the code would not run and an error message would appear since there are only 30 places for Tiles available . Nevertheless, the code ran normally, 30 tiles were put to the right order and that was all. My command referred to 60 tiles, what happened to the rest that have to be placed? The same question obviously applies when choosing Loop for 15 times. I am wondering, why does the code run normally in the above 2 cases?

3 Likes

I noticed that when I ran the first code without using loops the tiles flew in one by one very quickly with a consistent speed. When I ran the second code that used a loop there was a pause after each of the three tiles were placed. I’m wondering if this was a deliberate animation choice or if it was a result of looping.

In other words while it is much faster to code using the loop does it take more processing and/or result in a slower execution than writing it out many times?

The for loop tutorial (2/6) it says " When a computer receives this program it sets a counter to 0 and executes the instructions in the body of the loop. After each iteration (one pass through the instructions), it advances the counter by 1. The process repeats until the counter is 10, meaning 10 iterations are completed."

Given that the counter starts at 0, shouldn’t the process only repeat until the counter is 9? If a counter repeats from 0 to 10, isn’t that 11 iterations?

2 Likes

No, the little pause is just animation