Solving Problems ◾ 103
temp ← myDog
myDog ← yourDog
yourDog ← temp
Lest you think that patterns are unimportant. ink what would happen if
programmers did not know about the swap pattern and incorrectly assumed
that the following algorithm would work to swap myDog and yourDog:
myDog←yourDog
yourDog ← myDog
Swapping illustrates one kind of algorithmic pattern. Another, more
general, pattern of soware execution is known as repetition. Repetition is
used anytime a task needs to be repeatedly performed. Repetition is com-
mon in computer programs because one of the things that the computer
can do well is to repeat some process, no matter how mundane, over and
over. Soware developers might recognize a pattern of repeating some-
thing ve ti