Chunky Monkey help with the infinite

Tell us what’s happening:
I just don’t understand why this won’t work, how is it an infinite loop?

*edit, I solved it on my own with a whole other approach, but I still don’t understand what was previously wrong…

Your code so far


function chunkArrayInGroups(arr, size) {
  var array = [];
  var iter = Math.ceil(arr.length / size);
  
  for (var i=0; i<iter; i++) {
//newCodeBelow
    var x = i*size;
    array.push(arr.slice(x, x+size));
//newCodeAbove,oldCommentedCodeBelow
   /* for (var x=0; x<=arr.length-size; x+size) {
      for (var z=size; z<=arr.length; z+size) {
        array.push(arr.slice(x, z));
      }
    }*/
  }
  
       
  return array;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2)

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 OPR/50.0.2762.67.

Link to the challenge:
https://www.freecodecamp.org/challenges/chunky-monkey

Actually, after each loop, z is increased by size:
for (var z=size; z<=arr.length; z+size)
Therefor, z is never smaller or equal then the length of the array, z just keeps on getting bigger.
This happens with x before z too, so that’s why you’re getting an infinite loop warning at the line with the z-loop.

Edit: whoops my bad, wrong calculation there. z+size doens’t do anything in this loop, therefor @camperextraordinaire’s answer is correct. z is always equal to 2, which is always shorter than the length of arr (pirates!).