使用“中断”在一次通话中打破多个循环 [英] Using "break" to Break Out of Multiple Loops in One Call

查看:77
本文介绍了使用“中断”在一次通话中打破多个循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#是否支持PHP'的break命令,可选择

接受一个参数,指定要突破多少个循环?

解决方案

否 - ''break''和''continue''始终适用于最里面的循环。

你需要设置和测试标志来做你想要的(或者 - 喘气 - 转到)。

-
http:// www.tangiblesoftwaresolutions.com

C ++到C#

C ++到VB

C ++到Java

即时C#:VB到C#

即时VB:C#到VB

即时C ++:VB或C#到C ++ / CLI

Java to VB& ; C#转换器:Java到VB或C#

" O.B."写道:


C#是否支持PHP的break命令,可选择

接受一个参数,指定要断开多少循环?


2月15日18:31,OB < funkj ... @ bellsouth.netwrote:


C#是否支持PHP'的break命令,可选择

接受参数指定要突破多少个循环?



不是我意识到的,如果我发现了一个,那么在清除

代码时会有咕噜声......


for(;; int i(for(i = 0; i< 100; for(; console.writeline(" {0} \ n),i; f或(;; i +

+ for(;; break(2))))));

必须尝试......总有一天...它的工作很少但是给了一个例子

为什么不...它应该停止写什么,但谁知道...

// CY


< blockquote> OB写道:


C#是否支持任何类似PHP的break命令,可选择

接受一个参数,指定有多少循环到突然出现?



编号那个开头并不是很好(要求程序员小心计算
)。带标签的断点和Java会更好,但它也没有.b / b

如果你真的觉得它让代码更容易阅读,你可以随时使用

转到。如果多级中断,是处理一个罕见的错误条件,你

可能会抛出异常。如果是这种情况,那么你应该将b $ b分成多个函数。那也可以让你使用返回来回报
打破当前函数中的所有循环。


-

J.


Does C# support anything like PHP''s break command that optionally
accepts a parameter specifying how many loops to break out of?

解决方案

No - ''break'' and ''continue'' always apply to the innermost loop.
You will need to set and test flags to do what you want (or - gasp - goto).
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB or C# to C++/CLI
Java to VB & C# Converter: Java to VB or C#
"O.B." wrote:

Does C# support anything like PHP''s break command that optionally
accepts a parameter specifying how many loops to break out of?


On 15 Feb, 18:31, "O.B." <funkj...@bellsouth.netwrote:

Does C# support anything like PHP''s break command that optionally
accepts a parameter specifying how many loops to break out of?

Not that Im aware of, and there would be grunts in the cleraing of
code if I found one...

for(;;int i(for(i=0;i<100;for(;console.writeline("{0}\n",i;f or(;;i+
+for(;;break(2))))));
have to try that... someday... it sholdnt work, but giving an example
of why not.. it should stop at writing nothing but who knows...
//CY


O.B. wrote:

Does C# support anything like PHP''s break command that optionally
accepts a parameter specifying how many loops to break out of?

No. And that''s not very nice to begin with (requiring the programmer to
count carefully). Labeled breaks a la Java would be better, but it doesn''t
have that either.

If you really think it makes the code easier to read, you can always use
goto. If the "multi-level break" is to handle a rare error condition, you
could throw an exception instead. If that''s the case, though, you should
probably split things up in multiple functions. That would also allow you to
use "return" to break out of all loops in the current function.

--
J.


这篇关于使用“中断”在一次通话中打破多个循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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