updated loop condition