1 / 9

FOR LOOP WALK THROUGH

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 ( "*" ); } } } }.

trina
Télécharger la présentation

FOR LOOP WALK THROUGH

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FOR LOOP WALK THROUGH publicclassNestedFor{publicstaticvoid main(String [] args) { for (inti = 1; i <= 7; i++) {System.out.println();for (intj = 1; j <= i; j++) {System.out.print("*"); } } }}

  2. publicclassNestedFor// FIRST TIME THROUGH THE LOOP{publicstaticvoid main(String [] args) { for (inti = 1; i<= 7; i++) {System.out.println();for (intj = 1; j <= i; j++) {System.out.print("*"); } } }} i = 1 1 is less than or equal to 7 New line j = 1 1 is less than or equal to 1 Print * , increment, and loop 2 is NOT equal to 1 so fall out and return to outer for 01 02 * 03 04 05 06 07 08 09 10

  3. publicclassNestedFor// SECOND TIME THROUGH THE LOOP{publicstaticvoid main(String [] args) { for (inti = 1; i<= 7; i++) {System.out.println();for (intj = 1; j <= i; j++) {System.out.print("*"); } } }} 2 i = 2 2 is less than or equal to 7 New line j = 1 1 is less than or equal to 2 Print * , increment, and loop 2 is less than or equal to 2 Print * , increment, and loop 3 is NOT equal to 2, so fall out and return to outer for 01 02 * 03 ** 04 05 06 07 08 09 10

  4. publicclassNestedFor// THIRD TIME THROUGH THE LOOP{publicstaticvoid main(String [] args) { for (inti = 1; i<= 7; i++) {System.out.println();for (intj = 1; j <= i; j++) {System.out.print("*"); } } }} 3 i = 3 3 is less than or equal to 7 New line j = 1 1 is less than or equal to 3 Print * , increment, and loop 2 is less than or equal to 3 Print * , increment, and loop 3 is less than or equal to 3 Print * , increment, and loop 4 is NOT equal to 3, so fall out and return to outer for 01 02 * 03 ** 04 *** 05 06 07 08 09 10

  5. publicclassNestedFor// FOURTH TIME THROUGH THE LOOP{publicstaticvoid main(String [] args) { for (inti = 1; i<= 7; i++) {System.out.println();for (intj = 1; j <= i; j++) {System.out.print("*"); } } }} 4 i = 4 4 is less than or equal to 7 New line j = 1 1 is less than or equal to 4 Print * , increment, and loop 2 is less than or equal to 4 Print * , increment, and loop 3 is less than or equal to 4 Print * , increment, and loop 4 is less than or equal to 4 Print * , increment, and loop 5 is NOT equal to 4, so fall out and return to outer for 01 02 * 03 ** 04 *** 05 **** 06 07 08 09 10

  6. publicclassNestedFor// FIFTH TIME THROUGH THE LOOP{publicstaticvoid main(String [] args) { for (inti = 1; i<= 7; i++) {System.out.println();for (intj = 1; j <= i; j++) {System.out.print("*"); } } }} 5 i = 5 5 is less than or equal to 7 New line j = 1 1 is less than or equal to 5 Print * , increment, and loop 2 is less than or equal to 5 Print * , increment, and loop 3 is less than or equal to 5 Print * , increment, and loop 4 is less than or equal to 5 Print * , increment, and loop 5 is less than or equal to 5 Print * , increment, and loop 6 is NOT equal to 5, so fall out and return to outer for 01 02 * 03 ** 04 *** 05 **** 06 ***** 07 08 09 10

  7. publicclassNestedFor// SIXTH TIME THROUGH THE LOOP{publicstaticvoid main(String [] args) { for (inti = 1; i<= 7; i++) {System.out.println();for (intj = 1; j <= i; j++) {System.out.print("*"); } } }} 6 i = 6 6 is less than or equal to 7 New line j = 1 1 is less than or equal to 6 Print * , increment, and loop 2 is less than or equal to 6 Print * , increment, and loop 3 is less than or equal to 6 Print * , increment, and loop 4 is less than or equal to 6 Print * , increment, and loop 5 is less than or equal to 6 Print * , increment, and loop 6 is less than or equal to 6 Print * , increment, and loop 7 is NOT equal to 6, so fall out and return to outer for 01 02 * 03 ** 04 *** 05 **** 06 ***** 07 ****** 08 09 10

  8. publicclassNestedFor// SEVENTH TIME THROUGH LOOP{publicstaticvoid main(String [] args) { for (inti = 1; i<= 7; i++) {System.out.println();for (intj = 1; j <= i; j++) {System.out.print("*"); } } }} 7 i = 7 7 is less than or equal to 7 New line j = 1 1 is less than or equal to 7 Print * , increment, and loop 2 is less than or equal to 7 Print * , increment, and loop 3 is less than or equal to 7 Print * , increment, and loop 4 is less than or equal to 7 Print * , increment, and loop 5 is less than or equal to 7 Print * , increment, and loop 6 is less than or equal to 7 Print * , increment, and loop 7 is less than or equal to 7 Print * , increment, and loop 8 is NOT equal to 7, so fall out and return to outer for 01 02 * 03 ** 04 *** 05 **** 06 ***** 07 ****** 08 ******* 09 10

  9. publicclassNestedFor// EIGHTH TIME THROUGH LOOP{publicstaticvoid main(String [] args) { for (inti = 1; i<= 7; i++) {System.out.println();for (intj = 1; j <= i; j++) {System.out.print("*"); } } }} 8 i = 8 8 is NOT less than 7 Break from for loop 01 02 * 03 ** 04 *** 05 **** 06 ***** 07 ****** 08 *******

More Related