C++ Same name local variables keeping values between loops -


i have following 2 loops in c++ code:

for (int hcount = 0; hcount < height; hcount++)     {         (count = 0; count < width; count++)         {             cout << character;         }         cout << endl;     }  cout << endl;  (int hcount = 0; hcount < height; hcount++); {     (count = 0; count < width; count++)     {         cout << character;     }     cout << endl; } 

the problem running after using variable hcount in first loop, variable hcount in second loop initialize value had in first loop. not sure why both being initialized seem local variables , set equal 0.

the problem here:

for (int hcount = 0; hcount < height; hcount++); 

you end loop ;, no-op. hcount in case visible in scope of loop. after loop execution (i.e. after ;), inner loop starts executing. debugger displays last value taken hcount.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -