Do/while loop outside a function


#1

All of the do/while loops in the exercises are places inside an undefined function, e.g.:
var getToDaChoppa = function(){
// Write your do/while loop here!
};

getToDaChoppa();

Is it strictly necessary to have this outer function? If not, what is then the difference of the two? And what about the difference between placng my variable inside and outside the function?


#2

No, it is not. You can have a do/while loop or a for loop outside a function.

They are roughly the same, except that a function is a block of code you can call with a function call (getToDaChoppa();)

No huge difference, only you have to be careful with your variable scope (local vs global). Hope this helps.


#3

Yes, I think I understand now. Thank you.