Scope of a variable in a for loop

  • Thread starter Thread starter Torben Laursen
  • Start date Start date
T

Torben Laursen

Hi

I have a problem understanding the scope of a variable defined in a for
loop.
As I see it the code below should not compile since the variable i can only
be seen in the first for loop.
What did I not understand? thanks.
///code sniff, way can the second loop "see" the variable i?

for(int i=0; i<N; ++i)

{

SumKx += x;

}

for(int i2=0; i2<N; ++i2)

y = x;

Best regards
Torben Laursen
 
Back
Top