6. solo flight - soloLoop(); at the end?



my code works fine im just wondering what the soloLoop(); at the end is for

this is my code,

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


Practice makes perfect

Well functions are some sort of sub programs that do not run on their own but need a start command and that is the start command. On the other hand you can use them whenever you want and not just once. But maybe have a look at your condition, do you really feel comfortable with a function as a condition?



This is what is known as a function call it executes your function wherever you put the call.



ok that makes sense! need to look back at functions i guess. hurm yeah do you mean that i labelled the variable that equals 0 at the beginning and the function the same thing? i dont know why i did that.


Yes you should try different variable names, as it goes:

sL = true
sL = function
while(sL) // still a function
sL = false
while(sL) // now false -> exit

PS: Just out of pure curiosity. If you'd call the function for a second time, does it break because now sL is false and no longer a function? :slight_smile:


eheh i guess i just wasnt really paying attention there, makes sense !


ooh heres another question

if you get rid of the function part the code still works, it just prints out the number of times its looped afterwards too? why is that? for example,

var loop = function(){
	while(count < 3){
		console.log("I'm looping!");



while(count < 3){
		console.log("I'm looping!");

what they print is similar, so what is the function doing?


You're running it in a console so it repeats the last used value which is this:


in the first case. Which has a "value" of undefined (no value) as nothing is returned. And this:


in the second case.


soloLoop() is calling the argument.....You should go through the "function" part once...then you'll understand