40 likes | 169 Views
Introduction to Computers and Programming Lecture 10: For Loops Professor: Evan Korth New York University. Road map. Nested for loops Reading: Liang 6: Chapter 4: 4.6 Liang 7: Chapter 4: 4.6. Nested For Loops. It is also possible to place a for loop inside another for loop.
E N D
Introduction to Computers and ProgrammingLecture 10: For LoopsProfessor: Evan KorthNew York University
Road map • Nested for loops • Reading: • Liang 6: Chapter 4: 4.6 • Liang 7: Chapter 4: 4.6
Nested For Loops • It is also possible to place a for loop inside another for loop. int rows, columns; for (rows = 1; rows <= 5; rows++) { for (columns=1; columns<=10; columns++) System.out.print ("*"); System.out.println (); } Output: ********** ********** ********** ********** ********** Outer Loop Inner Loop
Nested For Loops, Example #2 int rows, columns; for (rows=1; rows<=5; rows++) { for (columns=1; columns<=rows; columns++) System.out.print ("*"); System.out.println (); } Output: * ** *** **** ***** Outer Loop Inner Loop