working out loops using yield function