Normalized loop: Difference between revisions

Content deleted Content added
m General Fixes using AWB
m Example 4 is not the last example in the above exmple list, since example 5 has been added.
Tag: gettingstarted edit
Line 82:
===Impossible conversions===
 
The lastExample example4 above makes it impossible to predict anything from that loop. Unless the functions themselves are trivial (constant), there is no way to know where the loop will start, stop and how much it'll increment each iteration. Those loops are not only hard to parallelize, but they also perform horribly.
 
Each iteration, the loop will evaluate two functions ('''max()''' and '''increment()'''). Even if the functions are inlined, the condition becomes too complex to be worth optimizing. The programmer should take extra care not to create those loops unless strictly necessary (if ever).
 
Another danger of such loops appear if the evaluation depends on the data being modified. For instance, a normal error when using iterators is to remove items from a list while modifying it, or relying on sizes (for exit condition) that are not true any more.