Well, because for-each is not designed to use an existing variable. The way for-each works, the variable gets a new value on each iteration, and therefore any pre-existing value of the variable is completely irrelevant. Therefore to avoid possible confusion, Java's designers decided to simply force users to declare a new variable as part of the for-each structure.
And I suggest to call it enhanced for loop, as far as we don't and won't have anything to do with .Net
posted 11 years ago
Except that "foreach" has been used in a number of other languages long before C# or other .Net languages, including some Unix shells and Perl. It's not something owned by Microsoft. [ February 28, 2008: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
Right! We're on it! Let's get to work tiny ad!
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps