FAQ: Loops - Nested Loops

2 posts were split to a new topic: Did I make an infinite loop?

2 posts were split to a new topic: My code doesn’t pass? [bug]

A post was split to a new topic: How do I get the last item in an array?

5 posts were split to a new topic: What happens if my arrays aren’t the same length?

4 posts were split to a new topic: Why doesn’t my nested loop work? [typo]

4 posts were split to a new topic: [typo] Nested loops

2 posts were split to a new topic: [typo] What is wrong with my nested loop?

2 posts were merged into an existing topic: FAQ: Why can’t I console log mutualfollowers.push()

4 posts were split to a new topic: [typo] Is there a typo in my nested loop?

A post was merged into an existing topic: FAQ: Why can’t I console log mutualfollowers.push()

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

Hi guys,

Could someone explain why when logging bobsFollowers[i] or tinasFollowers[j] to the console we get [ ‘Marta’ ]
[ ‘Marta’, ‘Sam’ ] instead of [ ‘Marta’, ‘Sam’ ][ ‘Marta’, ‘Sam’ ].