FOR LOOP WALK THROUGH
public class NestedFor{ public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println();
for (int j = 1; j <= i; j++) { System.out.print("*"); } } }}
public class NestedFor // FIRST TIME THROUGH THE LOOP{ public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println();
for (int j = 1; j <= i; j++) { System.out.print("*"); } } }}
i = 11 is less than or equal to 7
j = 11 is less than or equal to 1Print * , increment, and loop2 is NOT equal to 1 so fall out and return to outer for
New line
0102 *0304050607080910
public class NestedFor // SECOND TIME THROUGH THE LOOP{ public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println();
for (int j = 1; j <= i; j++) { System.out.print("*"); } } }}
i = 22 is less than or equal to 7
j = 11 is less than or equal to 2Print * , increment, and loop2 is less than or equal to 2Print * , increment, and loop3 is NOT equal to 2, so fall out and return to outer for
New line
0102 *03 **04050607080910
2
public class NestedFor // THIRD TIME THROUGH THE LOOP{ public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println();
for (int j = 1; j <= i; j++) { System.out.print("*"); } } }}
i = 33 is less than or equal to 7
j = 11 is less than or equal to 3Print * , increment, and loop2 is less than or equal to 3Print * , increment, and loop3 is less than or equal to 3Print * , increment, and loop4 is NOT equal to 3, so fall out and return to outer for
New line
0102 *03 **04 ***050607080910
3
public class NestedFor // FOURTH TIME THROUGH THE LOOP{ public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println();
for (int j = 1; j <= i; j++) { System.out.print("*"); } } }}
i = 44 is less than or equal to 7
j = 11 is less than or equal to 4Print * , increment, and loop2 is less than or equal to 4Print * , increment, and loop3 is less than or equal to 4Print * , increment, and loop4 is less than or equal to 4Print * , increment, and loop5 is NOT equal to 4, so fall out and return to outer for
New line
0102 *03 **04 ***05 ****0607080910
4
public class NestedFor // FIFTH TIME THROUGH THE LOOP{ public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println();
for (int j = 1; j <= i; j++) { System.out.print("*"); } } }}
i = 55 is less than or equal to 7
j = 11 is less than or equal to 5Print * , increment, and loop2 is less than or equal to 5Print * , increment, and loop3 is less than or equal to 5Print * , increment, and loop4 is less than or equal to 5Print * , increment, and loop5 is less than or equal to 5Print * , increment, and loop6 is NOT equal to 5, so fall out and return to outer for
New line
0102 *03 **04 ***05 ****06 *****07080910
5
public class NestedFor // SIXTH TIME THROUGH THE LOOP{ public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println();
for (int j = 1; j <= i; j++) { System.out.print("*"); } } }}
i = 66 is less than or equal to 7
j = 11 is less than or equal to 6Print * , increment, and loop2 is less than or equal to 6Print * , increment, and loop3 is less than or equal to 6Print * , increment, and loop4 is less than or equal to 6Print * , increment, and loop5 is less than or equal to 6Print * , increment, and loop6 is less than or equal to 6Print * , increment, and loop7 is NOT equal to 6, so fall out and return to outer for
New line
0102 *03 **04 ***05 ****06 *****07 ******080910
6
public class NestedFor // SEVENTH TIME THROUGH LOOP{ public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println();
for (int j = 1; j <= i; j++) { System.out.print("*"); } } }}
i = 77 is less than or equal to 7
j = 11 is less than or equal to 7Print * , increment, and loop2 is less than or equal to 7Print * , increment, and loop3 is less than or equal to 7Print * , increment, and loop4 is less than or equal to 7Print * , increment, and loop5 is less than or equal to 7Print * , increment, and loop6 is less than or equal to 7Print * , increment, and loop7 is less than or equal to 7Print * , increment, and loop8 is NOT equal to 7, so fall out and return to outer for
New line
0102 *03 **04 ***05 ****06 *****07 ******08 *******0910
7
public class NestedFor // EIGHTH TIME THROUGH LOOP{ public static void main(String [] args) { for (int i = 1; i <= 7; i++) { System.out.println();
for (int j = 1; j <= i; j++) { System.out.print("*"); } } }}
i = 88 is NOT less than 7
Break from for loop
0102 *03 **04 ***05 ****06 *****07 ******08 *******
8