Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • No other variable should share the name of a global variable.
  • A block should not declare a variable the same name as a variable declared in any block that contains it.

...

In this example, the programmer sets the value of the msg variable, expecting to reuse that it outside the block. Due to the reuse of the same variable name, however, the outside msg variable value is not changed.

...

Exceptions

When the block is small, although still not desirable, the danger of reusing variable names is mitigated by the visibility of the immediate declaration. Even in this case, however, variable name reuse is not desirable.

References