REF: replace do-while by more readable while