J
John Salerno
This is from Programming in the Key of C#:
"You can initialize multiple variables in the for loop:
for (int i = 0, j = 0; ...
But it's an either/or situation. If you declare one or more variables of
the same type, you can't do anything else in the initializer. You can't
initialize one and declare another:
for (i = 0, int j = 7; ... // Won't work!"
Ok, this explanation doesn't seem to make much sense to me. The
sentences sound completely independent of one another, and almost
contradictory. First off, *what* exactly is the either/or situation here?
The main thing that confuses me is the sentence "You can't initialize
one and declare another." It seems that this is exactly what the first
example is doing. What's the difference between the above examples that
the first one is valid and the second isn't? I feel like the "int" in
the first example might be a typo.
Basically, what are the rules for declaring/initializing variables in
the for loop? Can you only do one or the other, and that's what the
above is trying to say? It's that first example that has me confused.
Thanks.
"You can initialize multiple variables in the for loop:
for (int i = 0, j = 0; ...
But it's an either/or situation. If you declare one or more variables of
the same type, you can't do anything else in the initializer. You can't
initialize one and declare another:
for (i = 0, int j = 7; ... // Won't work!"
Ok, this explanation doesn't seem to make much sense to me. The
sentences sound completely independent of one another, and almost
contradictory. First off, *what* exactly is the either/or situation here?
The main thing that confuses me is the sentence "You can't initialize
one and declare another." It seems that this is exactly what the first
example is doing. What's the difference between the above examples that
the first one is valid and the second isn't? I feel like the "int" in
the first example might be a typo.
Basically, what are the rules for declaring/initializing variables in
the for loop? Can you only do one or the other, and that's what the
above is trying to say? It's that first example that has me confused.
Thanks.