Thread: C++ Help
View Single Post
Old 06-28-2009, 12:08 PM   #4 (permalink)
kmote
 

Join Date: Jul 2005

Location: England

Posts: 2,159

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: C++ Help

Code:
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv)
{
    for(int i = 1; i < 4; i++)
    {
        for(int j = 1; j < 4; j++)
        {
            printf("outer loop %d inner loop %d\n", i, j);
        }
    }
    return (EXIT_SUCCESS);
}
output:
outer loop 1 inner loop 1
outer loop 1 inner loop 2
outer loop 1 inner loop 3
outer loop 2 inner loop 1
outer loop 2 inner loop 2
outer loop 2 inner loop 3
outer loop 3 inner loop 1
outer loop 3 inner loop 2
outer loop 3 inner loop 3
Just a really simple demo which should clear up how nested loops work. Yes, you need to put your braces in the right place, indenting your code consistantly is a great way to make it really obvious.
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
kmote is online now