// three arrays of the same size will be used in parallel int grades[10] String fNames [10] String lNames [10] // contents at same index represent info about same object // Jan Smith is 85 fNames[0] = "Jan" lNames[0] = "Smith" grades[0] = 85 fNames[1] = "Dan" lNames[1] = "Jones" grades[1] = 90 fNames[2] = "Stan" lNames[2] = "Melchizadek" grades[2] = 99 //... ---------------------------- // parallel arrays for grades and names int grades[] = {85, 90, 99, 80, 73} string fNames[] = {"Jan", "Dan", "Stan", "Nan", "Ann"} string lNames[] = {"Smith", "Jones", "Melchizadek", "Brown" "Whitley"} // since arrays are same size, one for loop can go through them all // at the same time for (i = 0; i < grades.size; i = i + 1) print fNames[i] + " " + lNames[i] + "has " + grades[i] endfor ---------------------------- // assume we have these modules to set up // parallel arrays for names and grades int grades[] = getGradeList() string names[] = getNameList() string lookFor = prompt "Look up what name?" // searching based on user input // we have not yet found it int foundAt = -1 for (int i = 0; i < names.size; i++) if (names[i] == lookFor) then foundAt = i // record where we found it endif // note there is NO ELSE here // if it didn't match we just have to keep searching // we won't know it isn't there until the loop ends endfor // if foundAt is still -1 after the loop, we didn't find it if (foundAt != -1) then // since the arrays are parallel, if we found the name at this index // the matching grade will be at the same index print names[foundAt + " has grade " + grades[foundAt] else print "No such student" endif ---------------------------- // modules setting up parallel arrays for names and weights and ages string names[] = getNames() double weights[] = getWeights() int ages[] = getAges() // loop through checking for age and printing matching name and weight for (int i = 0; i < names.size; i = i + 1) if (ages[i] > 10) then print names[i] + "is " + ages[i] + " and weighs " + weights[i] endif endfor ---------------------------- // module setting up array of fruits string fruits[] = getFruits() // to be parallel new array must be the same size double prices[fruits.size] // get input from the user to fill the parallel array for (int i = 0; i < fruits.size; i = i + 1) prices[i] = prompt "How much does a " + fruit[i] + " cost?" endfor ---------------------------- // modules set up parallel arrays of words and how often to repeat string words[] = wordList() int times[] = timesList() // loop to go through the parallel arrays for (int i = 0; i < words.size; i= i+1) // loop to repeat the word the given number of times for (int j = 0; j < times[i]; j = j + 1) print words[i] endfor endfor