Aspects


vs


For-loop

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

While-loop

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
Cleaner

"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#"

Faster

"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)"

Others

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"

Cheaper

"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