In the book the if statement is inside the for loop.  You might want to check on that.