Use while instead of for