set loop control correctly.