A for loop is a control structure used by many programming languages to iterate over a range


A while loop is a control structure used in many programming languages to continuously execute a set of instructions as long as a particular condition is met.

Cleaner faster

Quality Example

"Edit just realized a while-loop may well be a lot cleaner than a for-loop for this"

from question "Getting the index of an array, multiple times, then storing them in an array c#"


"And now we know that for-loop is faster than while-loop"

from question "For-loop vs while loop in R"

"I have also found that a while-loop is faster than a for-loop"

from question "Why is an inverse loop faster than a normal loop (test included)"


Quality Example
Greater cost

"Also it seems like a for-loop is of greater cost to the compiler than a while-loop"

from question "For loops in Learn Python the hardway"


"The reason for the second case much slower on sorted data is that a while-loop is cheaper than the equivalent for-loop when there are zero iterations"

from question "What causes the performance difference between these two implementations of insertion sort?"

Back to Home
Data comes from Stack Exchange with CC-BY-SA-3.0