Home   Cover Cover Cover Cover
 

Inner statement blocks

If a name declared in an outer statement block could be redeclared in an inner statement block, this name would have different meanings at different places in the method. This would be confusing and the program would be difficult to understand.

However, it is also confusing if the same name is declared in disjoint statement blocks at the same level (which is allowed). The reason why this is legal is probably to allow loop variables with the same names in loops at the same level.

In principle, one should avoid having several declarations of the same name in a method.