Identifies correct for loop, inserts line before for loop in correct place