implement smart-loop and naive-loop