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'.

R

--
Using Opera's revolutionary email client: http://www.opera.com/mail/

Reply via email to