• Register
0 votes
119 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.9k points

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.

38.6k points

Related questions

1 vote
2 answers 77 views
77 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 morrisBson 3.2k points
0 votes
1 answer 9 views
9 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 game 4.6k points
0 votes
1 answer 31 views
31 views
Problem: Hello guys, I am trying to understand deeply how two variables work inside a for-loop or iterate simultaneously? Where to use it and what is the purpose of it in a program?
asked May 31 adamSw 11.3k points
1 vote
2 answers 108 views
108 views
Problem : I am very new to Programming. I have recently started learning C Programming. I have written below code but I am facing following error. Please find below my source code for your reference: #include <stdio.h> void myfirstfunct(int[6]); int main() {        ... use option -std=c99 or -std=gnu99 to compile your code` I am looking for the very expert advice on quickly fixing above error.
asked Apr 16 morrisBson 3.2k points
0 votes
1 answer 4 views
4 views
Problem: Hi there! I am new to the world of programming and learning loop constructs in C#. My concept for loops is clear but I just recently encountered a code somewhere in which for loop was initialized as follows: for(;;) { } I tried running that code, but it ... I make some mistake but I want to know more about &lsquo;for&rsquo; loops and all the possible ways in which it can be used. Thanks!
asked 2 days ago Sheeza 3.7k points