Community
    • Login

    Collapse/Extend switch/case

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 2 Posters 73 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • francis BaudouxF
      francis Baudoux
      last edited by

      Hello, in *.py or *.js file is it possible to collapse/extend ‘case’ block as for switch-if-else-… ?
      Thanks for help

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @francis Baudoux
        last edited by

        @francis-Baudoux ,

        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
        

        8e84e298-3f00-4195-999b-6391d382153d-image.png

        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
        }
        

        da795ee6-0f62-435a-a461-60a616d05e53-image.png
        … doesn’t fold on case

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

        d87299b8-2d0b-40d7-afce-c28090211dd6-image.png

        1 Reply Last reply Reply Quote 4
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors