variable scope in statement blocks

前端 未结 9 1830
梦如初夏
梦如初夏 2020-12-01 21:14
for (int i = 0; i < 10; i++)
{
    Foo();
}
int i = 10; // error, \'i\' already exists

----------------------------------------    

for (int i = 0; i < 10; i         


        
9条回答
  •  醉梦人生
    2020-12-01 22:14

    Or is just a case of nanny-state compilerism?

    Exactly that. There is no sense in "reusing" variable names in the same method. It's just a source of errors and nothing more.

提交回复
热议问题