Yes, it works and is a good thing to study as far as tracing through the values. However, considering that the OP is a newbie, it might put him down a road he's not ready to go down just yet (variable scope issues and static class variables). I imagine the OP is a newbie and the professor is teaching the class like a C/C++ professor would in the beginning (no classes, no constructors, so make everything static, make everything global, then later we'll get to variable scoping, but for now stick them all at the top). All fine.
Except that in for-loops, the OP already knows to declare them in the for-loop, but he likely does not know how the ramifications of that. I see an inevitable problem of the OP coding on auto-pilot and declaring i in the for-loop SOMETIMES and sometimes not. When that happens, the OP needs an error message, he doesn't need two separate i variables, each at different scopes.
So to sum up, my general rule of thumb for newbies is that i, j, and k are never declared outside of a function, are never static, and are ONLY to be declared and used in a for-loop. OR if you don't like that rule, then NEVER declare them in the for-loop.
When they are no longer newbies, they can bend these rules.