Skip to main content

Add Else Statement

Purpose

Adds the else block to the conditional.

Availability

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

Usage

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

    Note

    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 {

}