Community
    • Login

    Collapse/Extend switch/case

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 4.1k Views 2 Watching
    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 Offline
      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 Online
        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
        • francis BaudouxF Offline
          francis Baudoux
          last edited by

          Hello,

          Thanks a lot for your great and swift answer

          1 Reply Last reply Reply Quote 1

          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
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors