📜  js return vs break in for 循环 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:31.432000             🧑  作者: Mango

代码示例1
void f()
{
   int x = -1;
   while(true)
   {
     if(x == 0)
        break;         // escape while() and jump to execute code after the the loop 
     else if(x == 1)
        return;        // will end the function f() immediately,
                       // no further code inside this method will be executed.

     do stuff and eventually set variable x to either 0 or 1
     ...
   }

   code that will be executed on break (but not with return).
   ....
}