Javascript, while loop return

后端 未结 3 904
时光说笑
时光说笑 2020-12-20 17:54
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

3条回答
  •  佛祖请我去吃肉
    2020-12-20 18:30

    First of all your code should be inside a function. Secondly the return statement which u have written inside the for loop will execute the result only once and it will come out of the entire function.

提交回复
热议问题