This code crashes my browser


#1



https://www.codecademy.com/courses/javascript-beginner-en-NhsaT/0/5?curriculum_id=506324b3a7dffd00020bf661


when i press save and submit it just doesn't load and then i have to kill google chrome


for (var i = 5; i < 51; i+ 5) {
	console.log(i);
}


#2

Hey @drrake What you're doing is very dangerous,, constantly running the code without correcting the problem is causing infinite loops.

An infinite loop is caused when you don't increment a loop and your code is continually printing up and will never stop until you increment it or stop it manually.


#3

Try adding an equal sign after your + sign here..

(i += 5)


#4

sorry for the very late reply, i have been focusing on my coursework and have not had time to do any code academy, can you explain what the "=" symbol actually changes as when i ran it it worked completely fine
thanks


#5

i+5 computes a value here i is 5 +5 is 10. So you compute the value of ten but the value of i remains 5.
i+=5 on the other hand is a short cut for i=i+5 here again you compute the value 10 but you assign it back to i effectively increasing the current value of i by 5. This way i will grow with every loop until it reaches 55 where the condition is now false and the loop is quit.


My code keeps crashing my web browser, is this normal?
#6

I think @haxor789 has explained it very clearly. I was also offline for a bit. :sweat_smile:


#7

ahh thank you for the explanation