Add a hasMore call at the start of C for loops and after the loop body

Since the loop header initializes the index variable, the first hasMore check
needs to happen inside the loop instead of before the loop.  Since the final
increment happens after the last time the loop body runs, there needs to be
another hasMore test just after the loop body.