从C#中的内部嵌套循环退出 [英] Exit from internal nested loop in c#

查看:58
本文介绍了从C#中的内部嵌套循环退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用(goto)从内部循环退出以转到父循环以完成循环时,我可以使用哪个关键字或哪个单词?

例如:

for(i = 0,i< = 100,i ++)
{
for(j = 0,j< 20,j ++)
{
如果(j = 5)
goto .........?
}
}

When I''m using (goto) to exit from internal loop to go to parent loop to complete the loop, which keyword , or which words can i use ?

for example :

for(i=0 , i <= 100 , i++)
{
for(j=0 , j < 20 , j++)
{
if (j = 5)
goto .........?
}
}

推荐答案

我只会使用命令

I would just use the command

break;



您的goto语句在哪里.

-

你在说这个吗?



where your goto statement is.

--

Are you talking about this?

bool breakUsed = false;

for(i=0;i<=100;i++)
{
   if(breakUsed == false)
   {
      for(j=0;j<20;j++)
      {
         if(j==5)
         {
            breakUsed = true;
            break;
         }
      }
   }
}


您正在寻找中断 [ ^ ]语句.

您完全不需要goto.
You''re looking for the break[^] statement.

You don''t need goto at all.



使用中断;退出循环并继续;迭代到下一个元素.检查 [
Hi,
Use break; for exit loop and continue; to iterate to the next element. Check this[^] link.


这篇关于从C#中的内部嵌套循环退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆