FAQ: Loops - Nested Loops


#24

Maybe so, but it won’t be for long. Just keep pouring over the lessons, and reading as you go. Practice each new concept along the way so you can see more of the in’s and out’s. It all may look simple, but there are some hidden jewels in even the simplest of concepts.


#25

This is what I’m trying to do :slight_smile:

It’s all well and good me learning something in a lesson, but if i don’t practice and continue to build my knowledge of these concepts i’ll be forever amateur.


#26

This is my code:

const bobsFollowers = ['Friend 1', 'Friend 2', 'Friend 3', 'Friend 4'];
const tinasFollowers = ['Friend 1', 'Friend Two', 'Friend 3'];
const mutualFollowers = [' ']; 
for (let i = 0; i < bobsFollowers.length; i++) {
  for (let j = 0; j < tinasFollowers.length; i++) {
    if (bobsFollowers[i] === tinasFollowers[j]) {
      console.log(mutualFollowers.push(tinasFollowers[j]))
    }
  }
};

when i run the program… it just thinks indefinitely and never tells me if i got it correct. I have tried refreshing. Signing out and signing back in. Restarting the computer. Using a different internet connection. It only happens when i insert the loop. Does this mean that the loop is running infinitely? If so, how do i fix it?


#27

yep, you do indeed have an infinity loop.

you need to identify the mistake, there are only two possible lines which could cause an infinity loop.

you could study them? Or run them separately to see which loop is causing you problems, then you narrowed it down to a single line.