changing loop by simple condition checking.