General template machinery to insert for statements