Okay, this should do it.

It is a different way of implementing loops, though I suspect it'd be faster to return the number of bytes to skip rather than the number of loop ends.

However, I think because it's doing the skip recursively it might be possible to cache all the jumps it passes in one go rather than, say, having to calculate each one individually.