简体   繁体   English

中断条件以继续循环

[英]Break condition to continue loop

I don't how can i do when condition done and then continue loop 当条件完成然后继续循环时我不怎么办

(soory for incomprehensible Language xD) (无法理解的语言xD的来源)

In code 在代码中

for(var i=0;i<10;i++)
{
   if( // some condition)
      {
        //codee doesn't matter
      }
   else if ( // some condition )
     {
      //And NOW when code is here i want go to next repetition 
     }

}

When i try to use continue and break i have error 当我尝试使用continue and break我遇到错误

illegal break statement 非法中断声明

return too is bad because it doesn't move to next repetition 返回也很糟糕,因为它不会移至下一个重复

I hope that i write this ok .. thanks! 我希望我写得还可以..谢谢!

Try this: 尝试这个:

for(var i = 0; i < 10; i++)
{
    bool isCheckrequired = // some condition from else if you mentioned;
    if(!isCheckrequired)//Any code which needs to be executed comes under this condition
    {
        if( // some condition)
        {
            //codee doesn't matter
        }
    }
}

What i have done here first to check if anything needs to be done in particular iteration(by moving the condition you mentioned in your ifelse block to the top) and then if code needs to be executed in particular iteration then put that code into the if block. 我在这里所做的工作首先是检查是否需要在特定迭代中完成任何操作(通过将您在ifelse块中提到的条件移至顶部),然后如果需要在特定迭代中执行代码,则将该代码放入if中。块。

for(var i = 0; i< 10; ++i) {
    if ( /* some condition */) {
        //codee doesn't matter
    }
}

If you want to continue just don't do nothing and it will continue. 如果您想继续,那就什么也不做,它将继续。 If you really want a continue condition you could do the following: 如果您确实想要继续条件,可以执行以下操作:

for(var i = 0; i< 10; ++i) {
    if ( /* some condition */ ) {
        //codee doesn't matter
    }
    else if ( /* other condition */ ) {
        continue;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM