Javascript, while loop return
20,302
return
means end of function and return some value. Any statements after return statement will not be executed and the execution of a function will terminate at return statement. So, return
in your case will make the loop to execute only one and terminate it.
Author by
Andy Li
Updated on August 24, 2020Comments
-
Andy Li over 3 years
var i = 0; while(i < 100){ return "The number is " + i; i++; }
What is wrong with my return statement? Why can I return a string plus a variable?