goto语句问题 [英] problem of goto statement
本文介绍了goto语句问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在c#页面中有一个代码.
我想跳到if循环到while循环....
i have a code inside the c# page.
i want to jump if loop to while loop like this....
while (-------)
{
for (-----)
{
if (------)
{
--------
goto outer;
}
}
outer:
-------
---------
--------
}
但由于跳入循环而无法实现.
but its not possible due to jump inside the loop.
so have u any solution about it?
推荐答案
一个break
语句(而不是goto
)会导致您需要的效果.
Abreak
statement (instead of thegoto
) would cause the effect you need.
hii,
嘿,伙计,除了您的代码外,什么都不做
参见下面的示例代码
hii,
hey dude nothing to do other than your code
see below sample code
int i=0;
while (i < 70)
{
for (int j = 0; j < 100; j++)
{
if ( j == 87)
{
goto outer;
Console.WriteLine("in loop" + j.ToString());
Console.WriteLine("in loop" + (j+1).ToString());
}
}
outer:
Console.WriteLine("out loop" + i.ToString());
Console.WriteLine("out loop" + (i + 1).ToString());
i++;
}
Console.ReadKey();
这将始终打印
this will always print
Console.WriteLine("out loop" + i.ToString());
Console.WriteLine("out loop" + (i + 1).ToString())
希望你能得到想要的.
编码愉快
hope you will get what you want.
have happy coding
这篇关于goto语句问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文