On Wednesday, 5 September 2012 at 15:12:11 UTC, Jose Armando
Garcia wrote:
On Sep 5, 2012, at 6:13, "Regan Heath" <[email protected]>
wrote:
On Wed, 05 Sep 2012 13:55:32 +0100, monarch_dodra
<[email protected]
> wrote:
On Wednesday, 5 September 2012 at 12:43:26 UTC, Piotr
Szturmaj wrote:
Michel Colman wrote:
I have a very simple suggestion for breaking out of nested
loops.
I think it's already there:
http://dlang.org/statement.html#BreakStatement
"If break is followed by Identifier, the Identifier must be
the label of an enclosing while, for, do or switch
statement, and that statement is exited. It is an error if
there is no such statement."
I really wish there was a simple "break from current scope"
command. It would be kinda like "goto end of scope", just
cleaner...
You can lodge an enhancement request, example code:
void main()
{
label: {
// ..code..
writefln("code1");
writefln("break..");
break label; // jumps to "here:"
// ..code..
writefln("code2");
}
// break lands here
writefln("here");
}
Current error:
test.d(nn): Error: enclosing label 'label' for break not found
In fact, as any BlockStatement can be labeled you can argue
any BlockStatement label should be 'breakable'.
Haven't tried it but this maybe implementable using templates,
try and catch.
I say this because Scala, being a "functional" language
implements this as a library using closure, high order
function, try, catch and throw. Maybe a few other features.
-jose
R
--
Using Opera's revolutionary email client:
http://www.opera.com/mail/
It is implementable with a simple "label: do{}while(false);"
actually.
... Or a goto ...