The code continues until we reach the end of the elements within the array. The
problem lies when the iteration begins anew. The function call, count(), must be called to
determine the length of the array each time the iteration begins on a new index. In the
code shown in Listing 3–7, count() is called ten times, nine times too many. These are
unnecessary calls that can be replaced with a single call to count() before we reach the
for loop. The updated, optimized code is shown in Listing 3–8.