More Examples - Sneak Preview of Arrays
Searching a list of names, e.g. in an address book, for a particular name:
ask user for targetName
found = false
repeat while not found
get next name in list
if name equals targetName
set found to true
end if
end repeat
Actually, you also need to stop the repetition if you run out of names:
ask user for targetName
found = false
repeat while (not found) and (more names in list)
get next name in list
if name equals targetName
set found to true
end if
end repeat
An array is a single variable that can hold multiple items of data. If we had an array of names we could rewrite this as
ask user for targetName
found = false
counter = 0
repeat while (not found) and (more names in list)
get names[counter]
if names[counter] equals targetName
set found to true
end if
increment counter
end repeat
We will see more about this next week.