Language: add labelled break and continue statements#484
Open
chqrlie wants to merge 1 commit intoc2lang:masterfrom
Open
Language: add labelled break and continue statements#484chqrlie wants to merge 1 commit intoc2lang:masterfrom
chqrlie wants to merge 1 commit intoc2lang:masterfrom
Conversation
2020018 to
fa40579
Compare
Member
|
Why would you use 'continue X' instead of 'goto X' (which is also what we generate)? When I read the title of the PR, I expected something like: So that we insert labels etc. |
Contributor
Author
|
`continue X` expands to a goto but the label is not the same : the target label is inserted just before the } at the end of the block whereas the label X points to the `for` statement itself.
Your suggestion to accept `for`, `while` and `switch` in `break` statements is interesting. it is less general and has no prior art but would be especially useful for a `switch` statement inside a `for` loop. Supporting that requires some extra work as we cannot use the existing label list.
… On 1 Apr 2026, at 20:59, Bas van den Berg ***@***.***> wrote:
bvdberg
left a comment
(c2lang/c2compiler#484)
<#484?email_source=notifications&email_token=AE5F5KUPXLMATCVM764GTKD4TVRIZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIMJXGIZTCMZSHE4KM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2LK4DSL5RW63LNMVXHIX3POBSW4X3DNRUWG2Y#issuecomment-4172313298>
Why would you use 'continue X' instead of 'goto X' (which is also what we generate)? When I read the title of the PR, I expected something like:
for(..) { while (..) { switch (..) { case 1: break while; case 2: break for; case 3: break; } } }
So that we insert labels etc.
—
Reply to this email directly, view it on GitHub <#484?email_source=notifications&email_token=AE5F5KUPXLMATCVM764GTKD4TVRIZA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIMJXGIZTCMZSHE4KM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2LK4DSL5RW63LNMVXHIX3POBSW4X3DNRUWG2Y#issuecomment-4172313298>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AE5F5KSPDXRCXOZSA33MTZT4TVRIZAVCNFSM6AAAAACXIQFOCSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DCNZSGMYTGMRZHA>.
You are receiving this because you authored the thread.
|
Contributor
Author
|
|
cbfca24 to
d1f8486
Compare
* `break` and `continue` can take the label of an enclosing statement to break or continue directly, bypassing the nested code flow. * this feature is popular in many derived languages and will be added in C in the next version of the C Standard. * simplified flow analysis * add tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
breakandcontinuecan take the label of an enclosing statement to break or continue directly, bypassing the nested code flow.