A useful technique is loop inversion which consists in replacing a while loop by a repeat-until (do while) loop. The following example illustrates this conversion. Note that the if-statement may not be needed when the original loop always executes at least one iteration. Sign in to download ...
There exists a dependence from statement S1 to statement S2 in a common nest of loops if and only if there exist two iteration vectors i and j for the nest, such that 1 i < j or i = j and there is a path from S1 to S2 in the body of the loop, 2 Statement S1 accesses memory...
The chief advantage is that the error-handling code doesn’t obscure the real work of the function. Further, the cleanup code is in the main path so it gets executed each time the function runs and is therefore more likely to be correct, always a bonus since most error code isn’t thor...
In 1983, Tom Duff of Lucasfilm realized that code of this sort can be “simplified” in C by interleaving a switch statement and a loop. The result is rather startling, but perfectly valid C. It's known in programming folklore as “Duff's device”: i = 0; j = (N+3)/4; switch...
Author contribution statement All authors listed have significantly contributed to the development and the writing of this article. Funding statement This research did not receive any specific grant from funding agencies in the public, commercial, or not-for-profit sectors. Data availability statement Da...