Skip to main content

Widen Scope


Moves a variable declaration out of the parent code block, which makes it available in a parent scope.


Available on a variable declaration within a loop, or a conditional statement.


  1. Place the caret on a variable declaration.


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

    for (int i = 0; i < 10; i++) {
        // ...
    // 'i' does not exist here
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Widen Scope from the menu.

After execution, the Refactoring moves the variable declaration out of the current scope.

int i = 0;
for (; i < 10; i++) {
    // ...
// 'i' exists here
See Also