Nesting of Loops

The way if statements can be nested, similarly whiles and fors can also be nested. To understand how nested loops work, look at the program given below:

#include<stdio.h>
int main( ) 
{ 
    int r, c, sum ; 
    for ( r = 1 ; r <= 3 ; r++ ) /* outer loop */ 
    { 
        for ( c = 1 ; c <= 2 ; c++ ) /* inner loop */ 
        { 
            sum = r + c ; 
            printf ( "r = %d c = %d sum = %d\n", r, c, sum ) ;
        }
    }
    getchar();
    return 0;
}