Author Topic: How to Beat Down an "else" Statement in Three Keystrokes  (Read 7011 times)

Lisa

  • Senior Community Member
  • Posts: 238
  • Hero Points: 24
  • User-friendly geek-speak translator extraordinaire
How to Beat Down an "else" Statement in Three Keystrokes
« on: January 29, 2008, 04:43:50 PM »
Suppose you want to get from something like this:

Code: [Select]
       if ( cond ) {
          doSomething();
       } else {
          goSomewhere();
          doSomethingElse();
          comeBack();
          takeANap();
       }

To this:

Code: [Select]
       if ( cond ) {
          doSomething();
       }
       goSomewhere();
       doSomethingElse();
       comeBack();
       takeANap();

1. First, put your cursor on "else" and press Ctrl+Shift+Right to select it.
2. Press Enter.
3. Press Ctrl+Delete, and select Unsurround the code block.

Though Unsurround does not normally apply to "else" blocks, this example shows how you can manipulate your code to make a feature work for you in order to save time.