Codecademy Forums

FAQ: Loops - Nested Loops

3 posts were split to a new topic: Formatting for loops and variable declarations

2 posts were split to a new topic: Do I need to declare my variables inside a for loop?

4 posts were split to a new topic: [typo] My nested loop won’t work?

2 posts were merged into an existing topic: Why do the loops work? (How do they ever match?)

2 posts were merged into an existing topic: Why do the loops work? (How do they ever match?)

4 posts were merged into an existing topic: Why do the loops work? (How do they ever match?)

14 posts were split to a new topic: How deep can nested loops go?

why does this just keep running without stopping?
let bobsFollowers = [‘s’,‘m’,‘t’,‘z’];
let tinasFollowers = [‘s’,‘m’,‘a’,];
let mutualFollowers = ;
for (let i = 0; i < bobsFollowers.length; i++) {
for (let j = 0; j < tinasFollowers.length; i++) {
if (bobsFollowers[i] == tinasFollowers[j]) {
mutualFollowers.push (bobsFollowers[i])
}
}
};

Hello, welcome to the forum.

You never change the value of j, so the inner loop is infinite :slight_smile:

1 Like