[Solved] Performance difference between for, while and do while loop? [closed]


The overall semantics of all three iteration statements is the same once they have been compiled into binary code.

They just provide a different taste over the same thing. Performance depends on:

  • the complexity of the body of the loop
  • the complexity of calculating the end condition / next iteration step

Since they all provide both of them there is no performance difference per se in any of them. Unless you consider small irrelevant things that you shouldn’t care in any case.

There could be some optimization tricks that can be done according to the kind of loop but you shouldn’t rely on them, even because they could be compiler dependent, so meaningless from your point of view.

solved Performance difference between for, while and do while loop? [closed]