> why not just implement break for all blocks ?
That would change the meaning of an existing "break" used validly to break
from a loop.
> why not have multiple breaks? [example: break(2)]
That would be very susceptible to introducing bugs when innocently adding an
extra nest level... you'd need some kind of named break point, but then
you're back at "goto considered harmful"
> why? that's what I want to know ...
Most of the time it isn't an issue... break etc are mainly useful to exit
loops; as you say, for regular logic you can always refactor into a method,
and the IDE can do most of this for you by selecting the block you want to
move (i.e. it should handle the args etc).
If you *really* want, you could semi-refactor it in-place using a delegate;
this will /essentially/ use captured variables to do something like the "new
argument class" idea you mentioned, but keeps the code in-place; slightly
more expensive, though.
MethodInvoker someCode = delegate {
// foo
if(blob1) return;
// bar
if(blob2) return;
// blip
};
someCode(); // exec
Marc
Jon Skeet [C# MVP] - 28 Mar 2008 15:24 GMT
<snip>
> If you *really* want, you could semi-refactor it in-place using a delegate;
> this will /essentially/ use captured variables to do something like the "new
[quoted text clipped - 9 lines]
> };
> someCode(); // exec
My eyes! My eyes! (And yes, that's after pointing out the availability
of goto.)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Marc Gravell - 28 Mar 2008 15:35 GMT
lol; we'll have to host an "ugliest trivial code" compo some time ;-p
I never said it was great, just that it would technically work...
For myself, it'd be: right-click, refactor, extract method, [fix up any
oddities], move on.
Marc
Jon Skeet [C# MVP] - 28 Mar 2008 16:08 GMT
> lol; we'll have to host an "ugliest trivial code" compo some time ;-p
Tonight? :)
> I never said it was great, just that it would technically work...
Sounds like the motto for the ugliest code competition.
> For myself, it'd be: right-click, refactor, extract method, [fix up any
> oddities], move on.
:)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Marc Gravell - 28 Mar 2008 16:21 GMT
Nah, if there are any perl devs they'll win hands down... ;-p
Ignacio Machin ( .NET/ C# MVP ) - 28 Mar 2008 15:41 GMT
> <snip>
>
[quoted text clipped - 18 lines]
> Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
> World class .NET training in the UK:http://iterativetraining.co.uk
hey, My opinion is that IF it does exist is for a reason and you can
use it where it makes sense.
That said, I have never used it :)
<snip>
> why? that's what I want to know ...
Well, there's always "goto" if you really want it:
using System;
public class Test
{
static void Main()
{
int i = 5;
int j = 10;
if (i==5)
{
if (j==10)
{
goto done;
}
Console.WriteLine("Oo!");
}
done:
Console.WriteLine("Done");
}
}
However, I'd suggest that if you get into that kind of situation (with
20 local variables and nesting 6 levels deep) then you'd be a lot
better off refactoring into smaller methods anyway.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
> it seems a shame you can not do this:
>
[quoted text clipped - 92 lines]
>
> why? that's what I want to know ...
You can use return instead, refactor that piece of code in a method
alone.
You can refactor each of the pieces of code in a separated methods.
Or you can wrap the entire thing in a while(true) , then you can use
break; as y ou want, just make sure to put a break at the end of the
piece of code.
thanks for your thoughts
i learnt a thing or three