Rust has three keywords for structured goto (return, break, and continue), so just being likegoto isn’t enough on its own. The question is whether it’s the one “good” kind of goto that we already have (https://github.com/rust-lang/rfcs/pull/2046#issuecomment-311230800).
This is, however, not that good kind of goto. It’s going into a sibling block, not leaving a block it’s already in.
So you probably want to use
And rewrite it something like this:
'whole: {
if xxxx {
if yyy {
//do something
break 'whole;
}
}
//do something
}
The simple question is: why would you want this? I mean, genuinely… you can imagine arbitrarily complex primitives for control flow that would exactly fit some very specific use-case in some concocted situation. That’s not a good approach to language design, though.
In particular, your code, which looks like this, with a bit more descriptive labels:
if outer_condition {
if inner_condition {
do_something();
} else {
continue 'fallback;
}
}
'fallback: else {
do_something_else();
}
can be trivially rewritten as:
if outer_condition && inner_condition {
do_something();
} else if !outer_condition || outer_condition && !inner_condition {
do_something_else();
}
I fail to see how the proposed syntax could have any advantage: it merely makes interpreting control flow more difficult without adding any new functionality.
I think it's fair to assume the real case is slightly more complicated, such that it's not as obvious. For example, tweak it slightly to
if outer_condition {
let x = expensive();
if inner_condition(&x) {
do_something(x);
} else {
continue 'fallback;
}
}
'fallback: else {
do_something_else();
}
which doesn't translate to a "trivial" if-else, but does work cleanly with LBV:
'whole: {
if outer_condition {
let x = expensive();
if inner_condition(&x) {
do_something(x);
break 'whole;
}
}
do_something_else();
}
EDIT: I feel like the post below this completely missed my point -- I could copy-paste the same "I don't care about any particular concrete example; you can make it slightly more complete and that rewrite doesn't work" reply to it -- but I'll let the thread die by not making a new reply for that.