Chained Control Flow Statements: break [, break]... [,continue] #8434
Unanswered
Caracrist
asked this question in
Language Ideas
Replies: 2 comments 7 replies
-
Elegant! I want it in c++ too! |
Beta Was this translation helpful? Give feedback.
1 reply
-
See: |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The concept is to allow multiple
break
statements and an optionalcontinue
operation within a single line, as shown below:The
break
statements can exit loops orswitch
case blocks. The number ofbreak
statements is limited by the number of enclosing scopes, while thecontinue
statement can only appear once and must be the last in the sequence.The formal definition is (see subj):
This means that within a block of code, multiple
break
statements and an optionalcontinue
can be used at the end. None are mandatory, ensuring full backward compatibility.Typically, alternatives to this approach involve managing multiple flags, akin to a state machine spread across local variables, combined with many
if
statements to handle conditions in the right place. This can complicate both the code and its readability.Additionally, since each statement (
break
,continue
) is a distinct word, it can be highlighted in the IDE, showing its relation to the corresponding block (for
,foreach
,while
,switch
,do
). During debugging, these statements can be executed one by one, similar to how execution is handled insidefor (statements)
, with each part of the line being highlighted independently.Beta Was this translation helpful? Give feedback.
All reactions