Add Else Statement


Adds the else block to the conditional.


Available when the cursor is on an if statement that does not have corresponding else block.


  1. Place the caret on an if block that has no else block.


    The blinking cursor shows the caret’s position at which the Code Provider is available.

    if (a)
        return b;
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Add Else Statement from the menu.

After execution, the Code Provider adds the else block to the conditional.

if (a)
    return b;
else {