Collapse/Extend switch/case
-
Hello, in *.py or *.js file is it possible to collapse/extend ‘case’ block as for switch-if-else-… ?
Thanks for help -
Python:
match subject: case pattern1: # Code to execute if subject matches pattern1 pass case pattern2: # Code to execute if subject matches pattern2 pass case _: # Code to execute if no other pattern matches (the default case) pass
So yes, Python will fold on case statements.
JavaScript:
switch (expression) { case value1: // Code to be executed if expression === value1 break; case value2: // Code to be executed if expression === value2 break; // ... more case clauses default: // Code to be executed if no case matches }
… doesn’t fold oncase… BUT, that’s because it folds on BLOCKS, not STATEMENTS:
switch (expression) { case value1: { // Code to be executed if expression === value1 break; } case value2: { // Code to be executed if expression === value2 break; } // ... more case clauses default: { // Code to be executed if no case matches } }
-
Hello,
Thanks a lot for your great and swift answer
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login