Count iterations of a “for” loop in Python

I would like to know how many iterations of a for loop were executed. Is there an elegant way? I came up with this:

iterations_num = 0
for iterations_num, elem in enumerate(sequence, 1):
    # loop body...

gives the number of iterations of the loop executed. Alternatives that I considered:

  1. enumerate
for iterations_num, elem in enumerate(sequence):
    # loop body…
iterations_num += 1

but it doesn’t work when the sequence is empty.

  1. for/else
for iterations_num, elem in enumerate(sequence):
    # loop body…
else:
    iterations_num += 1

except it does not work when the loop is aborted with break (the number iterations_num does not include the aborted iteration)

  1. -1
iterations_num = -1
for iterations_num, elem in enumerate(sequence):
    # loop body…
iterations_num += 1

except it is rather ugly.

  1. Manual counter
iterations_num = 0
for elem in sequence:
    iterations_num += 1

    # loop body...

This actually works and is seemingly easier to read than enumerate(sequence, 1)