Terminate loops early when possible.