Should D have control-flow expressions? IS it possible?
ABrightLight
example at example.com
Sat Sep 12 05:06:30 UTC 2026
On Thursday, 10 September 2026 at 06:56:25 UTC, Meta wrote:
> This *does* work, but I assume it's a special case because
> exceptions unwind the stack. Hopefully I'm wrong:
>
> ```d
> void main()
> {
> for (auto i = 0; i < 10; i++) {
> (true && throw new Exception(""));
> }
> }
> ```
I think that this works because `throw new Exception("")` is
inferred `noreturn`, which is implicitly convertible to all
types. <https://dlang.org/spec/type.html#noreturn>
As for some of the rest there, D does have labeled break and
continue, but they cannot cross function scopes.
I agree that there is room for more escape continuations (besides
just exceptions and some limited labeling for gotos) than what is
currently in the language, but not sure which could safely be
added.
More information about the Digitalmars-d
mailing list