title: Infinite for loop with nested while loop in JavaScript
body: <p>I keep getting an issue with an infinite loop in both the FOR and WHILE loop. I am trying to nest a while loop that will stop running when the number given by allNum[i] reaches 1. I get an error that both my for and while loops have an infinite loop issue. I'm still learning how to use loops, I am not sure what I'm doing wrong.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let numbers = []
  
  //create a loop to iterate through the numbers array
  for (let i = 0, n = allNum.length; i &lt; n; i++) {
  
    //create a new variable to store sub arrays
    let subArr = [];
  
    //use a while to stop when the number is divided down to 1 and then store divisors in an array if (allNum[i] % n == 0) if true allNum[i]/n and subArr.push(n); if false n++
  
    while (allNum[i] &gt; 0) {
      let c = 2;
  
      //if true then divide the number by n and add the n (divisor) to subArr, in this case we have to try the same number again to divide by the new value of i so don't increase n
  
      if (allNum[i] % c == 0) {
        allNum[i] = allNum[i] / c;
        subArr.push(c);
  
        //if false then make n go up by 1 number
      } else {
        c++;
      }
  
    } //WHILE ENDS
  
    numbers.push(subArr);
    console.log(allNum[i]) //using for testing only
  } //FOR ENDS
  
  console.log(numbers, '&lt;- divisors &amp; array -&gt;', allNum); //using for testing only
  return numbers;
  }</code></pre>
  </div>
  </div>
  </p>