Programmers learn & share
0 votes
53 views

Problem :

Looking for solution of following doubt
if one for loop is nested within another, then the counter variables for the two loops should be
by (6.9k points)   | 53 views

1 Answer

0 votes

Solution :

Yes we can !! But one need to be aware of the scope of the i variable. if we call the outer i as i_out and the inner i as i_in, the scope of the i is as given below:

for(int i = 0; i < 10; i++)
{
     // i means i_out
     for(int i = 0; i < 10; i++)
     {
        // i means i_in
     }
     // i means i_out
}

You can say that they do not affect each other and their scope of definition is different from each other.

by (36.1k points)  
2,204 questions
2,608 answers
59 comments
241 users