What is the scope of the counter variable in a for loop?

前端 未结 4 850
灰色年华
灰色年华 2021-02-14 07:31

I get the following error in Visual Studio 2008:

Error 1 A local variable named \'i\' cannot be declared in this scope because it would give a different meaning

4条回答
  •  遇见更好的自我
    2021-02-14 07:50

    Yea. Syntactically: The new scope is inside the block defined by the curly strings. Functionally: There are cases in which you may want to check the final value of the loop variable (for example, if you break).

提交回复
热议问题