Proposal: remove continue-expression of while loops from the language

what about adding a new keyword ‘continuedefer’ (or maybe ‘loopdefer’, …) that defers a statement in a loop IFF the loop continues (explicitly with ‘continue’ or implicitly by reaching end of loop body). I think this would solve an issue initially stated by @matklad (and the edge case stated by @andrewrk in the comment), since it would allow to replace the while () : ([continue expression]) syntax with a keyboard based explicit control-flow. Also this concept of a conditional defer already existst in the language: ‘errdefer’

Could you explain why this would be better?
I simply don’t see the problem being solved here.

I’m personally not in favor of adding another keyword especially for such a niche issue. I’d rather get distinct types, ranged integers, matrix support, better type and numerical coercion/cast ergonomics. Better translate-c, better anytype, and plently of other proposal, those are all demonstrably useful, without a huge cost in some case, in terms of complexity, this seems not really important enough to warrant a new keyword

1 Like

Just voicing my opinion that, having read the reasoning presented in this and similar posts proposing that this syntax be removed, I am not convinced and remain against its removal.

1 Like

Just pointing out that a defer is already almost identical to the continue expression, with the one caveat that a defer will run when the loop breaks but the continue expression won’t.
The majority of loops in my experience are not affected by this difference and it isn’t hard to work around.

2 Likes