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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top