Hello,i just recently started trying to learn C++ and i got to nested loops and it got me confused, so if you could give me example on nested loops and explain what it does and how it does it,if you can, that would be most appreciated thank you.
This is a discussion on Help with nested loops(im a new programmer) within the C++ Programming forums, part of the General Programming Boards category; Hello,i just recently started trying to learn C++ and i got to nested loops and it got me confused, so ...
Hello,i just recently started trying to learn C++ and i got to nested loops and it got me confused, so if you could give me example on nested loops and explain what it does and how it does it,if you can, that would be most appreciated thank you.
Last edited by cuo741; 06-28-2010 at 10:57 PM.
As far as I know a nested loop is nothing more than a loop within another loop...
this loop will print values from 0 to 9.Code:for(int i = 0; i < 10; i++) printf("%d ", i);
now a loop within that loop
The first loop will execute 10 times. This will execute the inner loop each time the first loop executes, and the inner loop prints the values from 0 to 10 on the screen each time it is executed. In other words it will print 0 to 10 ten times. When control reaches the inner loop, it enters in a loop and only passes control to the first for loop once the variable j is not lower than ten, and then it repeats.Code:#include <stdio.h> #include <stdlib.h> #include <iostream> int main(void) { for(int i = 0; i < 10; i++){ printf("%d: ", i); for(int j = 0; j < 10; j++) printf("%d ", j); std::cout.put(0xA); } getchar(); return(0); }
Why are you using magic numbers?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^