Mettle

early-exitThe loop can leave before its trip count

Reported by --explain after a verdict.

mettle explain early-exit

A break or an early return means the number of iterations is not known when the loop starts. A kernel that processes eight elements per step could run past the element the loop meant to stop at.

Fix: where the search and the work are separable, do the work in a counted loop and the search in its own. A break on the last iteration costs nothing to keep scalar.

Related