8. When to 'while' and when to 'for' Infinite loop?



Hi, For this exercise I used this code, and it is killing the page. I don't think I logged an infinite loop, could someone tell me if I did? Thanks!

var understand = true;

while (understand =true){
	console.log("I like hotdogs!");
	understand = false;

for (var counter = 1; counter < 11; counter++) {


Re-read the first line:

while (understand =true){

The condition you wrote above is an assignment expression. Here, the variable understand is assigned a value of true. Also note that an assignment expression gives the value that was being assigned. So, understand =true gives true. And thus the while loop remains true and it becomes an infinte loop.

Do you know how to fix the problem? :wink:


I'm not sure if this was the best way to fix it, but I changed

while (understand =true){

to this

while (understand =false){

And it went through, is that what I should have done?


You need to use the equality test operator == :wink:


Oh, ok :slight_smile:, thanks for your help!