fix infinite loop when nested loop appear