ex5.3 - non-recursive implementation of takeWhile()