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 } }