calculation with loop condition