FAQ: Loops - Putting it All Together

This community-built FAQ covers the “Putting it All Together” 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 Putting it All Together

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!

ok…i’m on the Putting It All Together part of the Loops lesson and i’m looking at the examples for For Loops and While Loops and all i can think is “where the ■■■■ did those i’s and semi-colons come from?” Did i miss something? Maybe I’m having trouble putting two and two together, but the (i = 0; i < 10; i++) confused me and for the first time in this whole course, I’m completely lost…

23 Likes

Same. My gut interpreted it as the conditions that would read kinda of like this (but i’m not sure it’s correct):

FOR loop
for (i = 0; i < 10; i++) { //for index starting at 0; with up to 10 items indexed; repeat the index
placeTile(‘mint’)
placeTile(‘orange’)
placeTile(‘mint’)

WHILE loop
let i = 0; //let index start at 0
while (i < 10) { //run list until index reaches 10
placeTile(‘mint’)
placeTile(‘orange’)
placeTile(‘mint’)
i++ //repeat indexed tiles as above (just like the === means verify it’s really true, i’m guessing ++ means add up the items

It’d be great if someone could confirm or correct this :slight_smile:

5 Likes

A little modification on the previous response:

let i = 0
while (i < 10)
{
placeTile(‘mint’)
placeTile(‘orange’)
placeTile(‘mint’)
i++
}

//Corrected.

Looks like that confirmation has not been forthcoming.

i++

is the JS shorthand to increment i.

i++  <=  i += 1  <=  i = i + 1
3 Likes

Having trouble getting past the Review, it’s not loading the next page (assuming it’s a quiz)

When I click the “Up Next” button I get a white screen.

4 Likes

I’m having the same issue. Did you reach a solution? I ran the code correctly, but the Next button won’t pop up.

1 Like

So I have done the lab part of this lesson and completed the objectives. however, the next button is not lighting up.

I also had this problem, in the end I just got frustrated and refreshed the entire page. It then allowed the next button to light up. Not sure why it worked tho!

1 Like

i = (is for) iteration

2 Likes

Messing around with the numbers following the i and re-running the program helped me work it out. But i agree it came from nowhere

hi everyone
for loop
we write
for (i=0 ; i<10 ; i++)
{the instructions … }
my main quest is that we use i like variable but we didn t declare it as int or declare his category

I understand that:
i = iteration,
i=0 means start counter at 0,
i<10 means run the iterations until 10
i++ means to increment the iterations each time.

But I kind of learnt this from elsewhere, the tutorials didnt explain this properly, and there was even a question in the quiz about this!

18 Likes

This is a very helpful explanation. The breakdown is appreciated.

2 Likes

Thank you! I was really confused on the i++

1 Like

I am sorry to bother Mtf, but I am still confused as to what i++ is exactly. I am trying to understand your explanation, but I do not have any experience with anything like this.
I guess my main issue is that I do not understand the longhand code you wrote out describing i++. What do “<=” and “+=” mean in your code?
You wrote i++ is a shortcut to increment i, by increment do you mean it adds to i ? Is there any way you could break this down for me? I apologize for my ignorance, would love to understand this.
I thought I understood when Silviacoco explained that i++ may mean repeat, or add up, the index. As if “i” meant index. But from your reply I gathered that is not the case. I also read what Booga wrote about i meaning iteration, so that further confused me lol. I know I am asking a lot, but any help at all would be greatly appreciated!

It is a shorthand form of,

i = i + 1

which increments the current value represented by i.

i = 5
i++
console.log(i)    //  6
i++
console.log(i)    //  7

Note that the operation takes place immediately without need for assignment.

We can also decrement a value using -- operator…

i--
console.log(i)    // 6
i--
console.log(i)    // 5

BRB after I finish reading your post.

<=    less than or equal to (a relation test)

+=    augmentation assignment (assignment operator)

Eg.

a = 5
a += 5
console.log(a)    //  10

It is the short form of writing,

a = a + 5

Yes, but it adds only 1, which is the default increment value. Typically, when we read, increment the value we assume it will grow by 1. The term could be used with other values, but ++ will not work for them.

a = 10
// increment a by 5
a += 5

Augment means to increase.

It is typical to see i used as the iteration variable though we could use any variable with the same effect. In the for loop we are iterating over each index as the value for i increases to the length of the object.

1 Like

Wow you are good ! Thank you very much for the help !!! I am not sure what was blocking me from understanding this in your first reply, I might have been overthinking it lol. I wrote everything you just shared in my notes, you cleared it all up for me. I am extremely grateful !! edit: I must thank you again for taking the time to thoroughly explain everything. I am sorry to have taken up your time with all my questions lol. The way you just broke everything down was a MAJOR help !!! I can comfortably move on fully understanding, I appreciate you very much.

1 Like

You are very welcome. It’s good that you took the time to grapple with the concepts rather than steaming ahead. Keep going back and reviewing, while at the same time exploring a little more each concept. Eventually they become second nature, but not without lots of practice. Work with small snippets and hammer out the meaning and purpose so that gradually you begin to see the bigger picture. Time and effort. Never be in a hurry.

4 Likes

You are very considerate, thank you for the priceless advice ! I will apply, and take note of everything you generously shared here. Its funny how our minds are a lot like computers, takes real programming to learn lol. Like you said with constant practice and exploring it should become second nature. I gained some incredible notes from your help here in the forums so far, thank you very much !!

1 Like