proposal-do-expressions: Clarify interaction between do-expressions and break
What does break; do inside a do-expression inside a loop? @ljharb and I had opposite intuitions, both of which seem reasonable (to me). (See issue #22.)
The proposal says,
Tennant’s Correspondence Principle
[…]
(do { <stmt> };)equivalent to{ <stmt> }
I take this to mean that (do { break; }); is equivalent to break; and therefore do-expressions are invisible to break. (To me, the use of the phrase “Tennant’s Correspondence Principle” indicates that this is intentional; maybe @dherman can confirm or deny?)
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 1
- Comments: 18 (9 by maintainers)
I read the whole thread and agree
(do { break; });should equalsbreak;.. But I also suspect maybe we should makedo { break; }syntax error just like currenteval('break;')if there is no strong use cases.The only near-real use case in this thread is
But I feel this example just show the dark side of allowing direct continue/break in the do block. It’s not easy to recognize there is a
continuestatement inside and actually dismiss thepushoperation. As a code reviewer, I would prefer the plain code likeMuch simpler, shorter and clearer.
Hope someone can give some good use cases.