# if one for loop is nested within another, then the counter variables for the two loops should be

201 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

## 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.

## Related questions

1 vote
406 views
Problem : I am very new to programming world. According to my senior a for loop will always get executed at least once even if a required condition is not met. Please find below example for your reference: for (int i=6; i <=5; i++) {     //inappropriate for this ... } According to my senior above listed loop will be executed at least once but it does not or let me know if I am I missing something?
5 views
45 views
Problem: My programming teacher gave us an assignment in which we have to tell which of the three loops in C++ does not have an entry condition? As far as my guess is concerned, the 'for' loop does not need an entry condition. I want you to guide me if I am wrong and tell me the correct answer to this question. Thanks!
3 views
Problem: Anyone here who know nested loops to print a rectangle. sample output for given program? If yes, then please answer me.
1 view
Problem: I am stuck with this ... Please help me that how to deal with this error? which loop structure always executes at least once?
6 views
48 views
Problem: I just started Bachelors in Software Engineering. Programming is the main subject of Software Engineering and I have no prior knowledge of programming. My programming teacher gave me an assignment in which I have to write a program in C++ whose output should be as ... a hint: Use nested loop. If someone knows how to do this kindly explain and provide me with the example program. Thanks.