Re: Using "break" to Break Out of Multiple Loops in One Call
Tech-Archive recommends: Fix windows errors by optimizing your registry
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.
.
Relevant Pages
- Re: identifiers and modules
... >> I did that in C more than once, and ran into problems with Java. ... >> or something that makes me more likely to produce subtle errors, ... If the loops are not nested, then the loop variable scopes do ... The difference of opinion probably relates to how different programmer ... (comp.lang.scheme) - Re: Value of inheritance in Object-oriented programming
... Timofei Shatrov wrote: ... which has no control flow constructs at all: all ifs and switches ... How do you make loops? ... which can do entirely different things if the programmer wants it. ... (rec.games.roguelike.development) - Re: Total Common Numbers
... I am not a programmer but have looked through the code that you have ... two different lists and tallying the appropreate results is. ... it would be best to use a smaller pool of numbers. ... agrees with the value you posted from your loops. ... (microsoft.public.vb.general.discussion) - Re: looking for thoughts on the philosophy of optimizing compilers
... the compiler removes it entirely. ... On most processors there should be a clock cycle counter or timestamp ... that sometimes you need such loops, ... A human programmer should investigate ... (comp.lang.c) - Re: Why does the try statement (and catch clause) require a block?
... simple statements for try blocks but requiring compound statements if ... simple or compound. ... loops, and `foreach` loops, each of which can declare a ... `foreach` loops *must* declare a ... (microsoft.public.dotnet.languages.csharp) |
|