Minimize 'for' into 'while'