move conditioanl into loop