Use a while loop instead of collection methods chaining.