Nested FOR loops are often used to produce DESIGNS:
// Isosceles Right Triangle (made with capital letters)
char outer, inner;
for (outer = 'F' ; outer >= 'A' ; outer--)
{
for (inner = 'A' ; inner <= outer; inner++)
{
System.out.print(inner);
}
System.out.println( );
} |
ABCDEF
ABCDE
ABCD
ABC
AB
A |
// Rectangle comprised of x's
int rows, col;
for (rows = 0; rows < 4; rows++)
{
for (col = 0; col < 12; col++)
{
System.out.print("x") ;
}
System.out.println( );
} |
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx |
|