nested for loops
 

Nested FOR loops are often used to produce DESIGNS

// The Isosceles Right Triangle (made with capital letters)
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
for (rows = 0; rows < 4; rows++)
{
for (col = 0; col < 12; col++)
{
System.out.print("x") ;
}

System.out.println( );
}

xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx

(c) Shilpa Sayura Foundation 2006-2017