DEV Community

Discussion on: What The For Loop?

 
kodikos profile image
Jodi Winters

If you're talking optimization, having the if statement (branching) is the most expensive thing, because it requires the processor to dump and reload its entire register state, and kills off the ability for it to pipeline nicely. Getting rid of the conditional is by far the most optimal solution to this code.