Buggy Ex1.8

Code runs in an infinite loop; needs to be fixed.