Thursday, January 10, 2002 05:47 AM
This question has come up before, and I have responded the same way:
The bytecode turns out to be identical.
Java stores local variables in known locations on the stack. When you get down to the bytecode level, there is no variable declaration, only a place in the stack where that variable will be.
Since the stack is allocated once (just before the method code actually starts executing), all local variables "exist" through the entire method, whether or not they are "declared yet" in your Java source code.
Hence, you should write your code so that it is more readable (that is, probably with the declarations within the loop, since those variables are not used outside of it).
Hope that helps,