• Register
0 votes

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.

36.1k points

Related questions

1 vote
2 answers 42 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
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.2k points
1 vote
2 answers 49 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
2 votes
1 answer 23 views
Problem: Hi all, I am an entry-level student in Python programming. I have got an assignment from my lecturer to write a program that prints a diamond shape made of *. Well, I want to learn from the very basics. As I understood it might be the very basics of printing ... to write a nested loop program to print a rectangle. sample output for the given program below: * * * * * * Thanks in advance
asked Mar 17 Gavin 15.2k points
0 votes
1 answer 12 views
Problem: Hello kodlogs, How can we use for loop in the python to iterate over the sequence of element I have a confusion over the range() function and the datatype like list, tuple and string. Like how can we access the elements in the list
asked Jun 9 Gavin 15.2k points