Simplify loops

Modify "if..do...while" to "while" (redundant conditions).