correct(?) implementation of the end conditions for iteration with blocks