I'm working my way through Head First C#, and I'm a bit confused on my current exercise. They state:
If you declare a variable inside a for loop--for (int c = 0; ...)--then that variable's only valid inside the loop's curly brackets. So if you have two for loops that both use the variable, you'll either declare it in each loop or have one declaration outside the loop. And if the variable c is already declared outside of the loops, you can't use it in either one.
This sounds contradictory to me, almost like saying you can only use it outside if you declare it outside, but if you declare it outside you can't use it.
So can you, or can't you? I tried declaring c in two separate for loops and it worked fine, but when declaring c outside of the for loops I couldn't find any way to reference the variable c inside both for loops while it's also declared outside, whether I was trying to change its value or not. This isn't required for the exercise, I'm just trying to soak up every bit of knowledge I come across and trying to go beyond the material.
The book may be confusing me, so if this isn't possible and is completely unnecessary, just let me know, thanks!