继续; 曾经跳过很多循环

Flo*_*Flo 3 c# loops continue

这是我的代码的架构:

while (..)
{
   for (...; ...;...)
        for(...;...;...)
            if ( )
            {
                 ...
                 continue;
            }
} 
Run Code Online (Sandbox Code Playgroud)

继续做什么?他只会让第二次循环迭代一次,不是吗?我希望它能够达到目标,是否可能?

谢谢!

Mar*_*ell 5

continue此影响最近的循环-你的第二个for.有两种直接跳转方式while:

  • goto虽然有时"被认为是有害的",但这可以说是它仍然存在的主要原因
  • return

为了说明后者:

while (..)
{
    DoSomething(..);
}

void DoSomething(..) {
    for (...; ...;...)
      for(...;...;...)
          if ( )
          {
             ...
             return;
          }
}
Run Code Online (Sandbox Code Playgroud)

和前者:

while (..)
{
   for (...; ...;...)
        for(...;...;...)
            if ( )
            {
                 ...
                 goto continueWhile;
            }
   continueWhile:
       { } // needs to be something after a label
}
Run Code Online (Sandbox Code Playgroud)