in this kind of iterations, always test against null as well.
if something bad happens, this way you won't end up in an infinite loop