Chapter 9 - Nested loops and two-dimensional arrays. In this chapter we will: show how nested loops are useful, introduce two-dimensional arrays, describe the use of two-dimensional arrays to represent grids of information, show how computer graphics are generated using pixels.
Chapter Nested Loops and Two-Dimensional Arrays Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N Kamin, D Mickunas, E Reingold Chapter Preview In this chapter we will: • show how nested loops are useful • introduce two-dimensional arrays • describe the use of two-dimensional arrays to represent grids of information • show how computer graphics are generated using pixels Nested for Loops • Nested loops frequently used to process twodimensional arrays • Often body of inner loop is where the main computation is done • Example: for (i = 0; i < m; I++) { before inner loop for (j = 0; j < n; j++) body of inner loop after inner loop }; Dependent for Loops • Sometimes the extent of the inner nested loop will depend on the index value of the outer loop • Example: for (i = 0; i < 3; i++) { out.print(“i= “; + i + “: j = “); for (j = 0; j