6. (While loop) solo flight


I'm very very confuse with this practice :frowning: HELP!!!

(syntax error.)

var condition= true
var soloLoop = function(){ while (condition)console.log("Looped once!"); condition = false;



The basic problem you have is you are missing a closing curly brace "}" for you while loop. Also your code is poorly formatted. I would change it so it looks more like this:

var condition = true;
var soloLoop = function(){ 
    while (condition) {
    console.log("Looped once!"); 
    condition = false;




that's great. thank you. it worked now.


As @mkordik already said, the problem is a lack of curly braces.
Just some additional information about what is happening.
The problem here is that it actually works to omit the curly braces, but in this case the keyword (while,for,if,else,...) only reaches on to the very next statement. Which leads to this:

var condition = true;
while (condition) { // just to illustrate the scope
    console.log("Looped once!"); 
} // just to illustrate the scope

which is obviously an infinite loop and which prevents you from reaching the statement that sets the condition to be false.


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