scope of local variable in enhanced for-loop

后端 未结 5 1152
执念已碎
执念已碎 2021-01-18 02:00

I have a rather simple question about variable scope.

I am familiar with the Enhanced For-Loops but I do not get why I should declare a new variable to keep each el

5条回答
  •  借酒劲吻你
    2021-01-18 02:38

    I don't think anyone has answered the original question beyond just declaring that that is the syntax. We all know that that is the syntax. The question is, logically speaking, why? After all, you can use a variable defined just before a loop as the loop variable, as long as the loop is a non-enhanced for loop!

提交回复
热议问题