【发布时间】:2013-07-09 13:47:31
【问题描述】:
我有以下代码:
foreach(// Some condition here)
{
while (// Some condition here)
{
foreach (// Some condition here)
{
if (// Condition again)
{
//Do some code
}
if (// Condition again)
{
//Stop the first foreach then go back to first foreach
}
}
}
}
我想要做的是,当我在最后一个 foreach 循环上点击第二个 if 语句时,是在第一个 foreach 循环上返回。
注意:如果第二个if 语句不为真,它应该继续最后一个foreach 循环,直到条件不为真。
提前致谢!
【问题讨论】:
-
放入一个方法并返回
-
在我看来像一个递归函数..
-
不会
break;帮忙吗? -
@rapsalands
break只会退出当前循环,在这种情况下是最里面的foreach。 OP想要退出两个内部循环,即最里面的foreach和while。
标签: c# loops if-statement foreach while-loop