Module 3: Arrays and For Loops

CMPS 162: Introduction to Programming


It is useful to store numbers and strings in variables such that you can operate on them. But what should we do if we want to keep a list of numbers (e.g., grades) or a list of strings (e.g., student names)? It would be very inconvenient to define a variable for each grade or each student name, and it also assumes we know in advance how many there will be. We need a better way and this can be achieved through arrays. An array is a fundamental data structure that each language has in one form or another that can store multiple things, i.e., it is a composite data type. It will grow in size when adding items and it shrinks when removing items. We also need a convenient way to inspect all element in the array (i.e., to calculate average grades) and this can be done through for loops. Being able to write for loops to solve simple problems with arrays is a very important skill to develop in this module.

Module Objectives

  • Describe Arrays
  • Show adding and removing elements with arrays
  • Show removing and inserting elements with arrays
  • Describe for loops
  • Explain flags, Booleans, and array length used in for loops
  • Apply nested for loops

Learning Resources

  • Module 3 Readings: Chapters 15 thru 20 from Myers

Learning Activities

  • Module 3 Assignment: Interactive Coding Exercises 15 thru 20


For Further Study

  • Read more about arrays on Wikipedia
  • Read more about for loops on Wikipedia

Leave a Reply

Your email address will not be published. Required fields are marked *