Simple while loop


#1


What is wrong in the following loop? Isnt the loop supposed to end after console.log? (because 'test' gets a new bool value "false" after looping once? But insted the website is crashing i presume because its a infinite loop? or did I understand the while loop wrong?


for (i=0; i <5; i++){
    console.log(i);
        
--->          test = true;
                   while (test)
                    console.log("YOLO");
                       test = false;
};


#2

the curly bracket around while are missing:

while (test){
  console.log("YOLO");
  test = false;
}

i think the missing {} is what is causing the infinity loop


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.