added iterative version of the excercise