Proposal: otherwise #8171
Replies: 2 comments
-
I can't understand the execute conditions of each branch by reading your code and comment.
Or if the block is extracted as a function:
However, it is not so common to have such statements to execute before testing for next condition. If there is any, the existing forms are more understandable. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for the feedback. The pointlessness of this idea has definitely become clear to me. |
Beta Was this translation helpful? Give feedback.
0 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.
-
General Idea
The otherwise keyword is introduced to complement the existing if-else syntax. It provides a more natural language approach to conditional statements, making the code easier to read and understand. The otherwise keyword is designed to be used in conjunction with if and else if statements to handle alternative conditions.
Semantics
if (condition): Executes the block of code if the condition is true.
otherwise: Executes the block of code if the preceding if or else if condition is false. This provides an alternative action specific to the previous condition.
else if (condition): Executes the block of code if the initial if condition is false and this new condition is true.
else: Executes the block of code if all preceding if and else if conditions are false.
Benefits
Improved Readability
Clearer Intent: It clarifies the programmer's intent by explicitly separating different alternative actions associated with specific conditions.
Maintainability: Easier to maintain and understand complex conditional structures
Potential Issues
The existing else keyword would need to coexist with otherwise, which could potentially confuse some developers
Beta Was this translation helpful? Give feedback.
All reactions