It keeps on saying that there is a potential infinite loop in the code. Is there something wrong with how I wrote the for loop? Can't figure out why this number isn't factorializing :confused:
```
function factorialize(num) {
if (num==0){
return 1;
}
for (var a =1;a<num;a++){
num+=a;
}
return num;
}
factorialize(5);
Hey Jack,
You’re increasing the num size in each loop. num+=a is taking 5 and adding whatever a is to it so a will always be less than num and the loop will never exit.
1 Like
Thanks for the feedback!! I changed the + to a * (total d’oh! moment), but I’m still not quite sure why the loop increases the size of num. I think I have to google some more about how loops work 
Loops are hard to wrap your head around unless you see some visual representation of what’s going on.
I’ll try and show what your loop is doing.
Your loop starts out as:
for(var a = 1; a < num; a++)
Beginning for first loop:
(a < num) - > (1 < 5) --> True --> Loop
(num += a) -> (num = 5 +1) -> (num = 6)
(a++) -> (a= 1 + 1) -> (a=2)
End first loop
Begin Second loop:
(a < num) - > (2 < 6) --> True --> Loop
(num += a) -> (num = 6 +2) -> (num = 8)
(a++) -> (a= 2 + 1) -> (a=3)
End second loop
Begin Third loop:
(a < num) - > (3 < 8) --> True --> Loop
(num += a) -> (num = 8 + 3) -> (num = 11)
(a++) -> (a= 3 + 1) -> (a=4)
End third loop
You see how (a < num) will never = false? That being false is what allows the for loop to exit, if it’s never false it will go on forever or what’s called an infinite loop.
Also, I recommend using Console.log within loops to figure out what’s going on. If you put the below code into your for loop you can see what’s going on in the console (ctrl + shift + i to open Dev Tools in Chrome):
console.log('num: ’ + num + ’ ’ + 'a: ’ + a);