这是我的代码架构:
while (..)
{
for (...; ...;...)
for(...;...;...)
if ( )
{
...
continue;
}
}
接下来会做什么?他只会让第二个循环迭代一次,不是吗? 我希望它能达到 while,有可能吗?
谢谢!
最佳答案
此处的 continue
会影响最近的循环 - 您的第二个 for
。有两种方法可以直接跳转到while
:
goto
,虽然有时“被认为是有害的”,但这可以说是它仍然存在 的主要原因
返回
为了说明后者:
while (..)
{
DoSomething(..);
}
void DoSomething(..) {
for (...; ...;...)
for(...;...;...)
if ( )
{
...
return;
}
}
和前者:
while (..)
{
for (...; ...;...)
for(...;...;...)
if ( )
{
...
goto continueWhile;
}
continueWhile:
{ } // needs to be something after a label
}
关于c# - 继续;用于跳过许多循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4826576/