solved loop condition