• Register
0 votes
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
6 5 3
6,930 points

Please log in or register to answer this question.

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.

9 7 4
38,600 points

Related questions

1 vote
2 answers 406 views
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?
asked Apr 6, 2020 morrisBson 3.2k points
0 votes
1 answer 5 views
5 views
Problem: Can anyone help me about this? If anyone know about loop to print each contact and contact email. Then please read my question carefully and answer me.
asked Mar 26 niyatiry 2.9k points
0 votes
1 answer 45 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!
asked Dec 17, 2020 Code Learner 9.2k points
0 votes
1 answer 3 views
3 views
Problem: Anyone here who know nested loops to print a rectangle. sample output for given program? If yes, then please answer me.
asked Mar 27 niyatiry 2.9k points
0 votes
1 answer 1 view
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?
asked Apr 2 Ifra 24.4k points
0 votes
1 answer 6 views
6 views
Problem: Can anyone help me about this? If yes, then please answer me.
asked Mar 26 niyatiry 2.9k points
0 votes
1 answer 48 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.
asked Nov 29, 2020 Code Learner 9.2k points
0 votes
1 answer 6 views
6 views
Problem: Please help me &hellip; how can I solve it? When using multiple nested cursors, what kinds of loops can you use?
asked Mar 31 Ifra 24.4k points
0 votes
1 answer 6 views
6 views
Problem: Please help me to solve it&hellip;. java for loop increment by 2
asked Mar 25 Ifra 24.4k points
0 votes
1 answer 12 views
12 views
In the first loop that runs with ++ of the function it returns 29 and the second that runs with + i returns 30, but both should return 29. What am I doing? #include <iostream> using namespace std; int sumElements (int a [], int size) {      int accum = 0;      int * p;      p = & a [0]; ...      } int main () {      int array [5] = {4,9,6,7,3};      cout << sumElements (array, 5);      return 0; }
asked Aug 14, 2020 game 4.6k points