Let\'s say I want to iterate over all integers in a for loop. For the sake of discussion, assume I am calling some unknown function f(unsigned x) f
You can do it with a do-while loop, but you lose all the niceties of the for syntax.
It is still doable with do-while loop by using an anonymous block scope:
{
unsigned i = 0;
do { f(i); } while (++i != 0);
}
While this construct may not be most idiomatic, it is an obvious candidate for clear assembly code. For example, gcc -O compiles it as:
.L2:
mov edi, ebx ; ebx starts with zero
call f
add rbx, 1
cmp rbx, rbp ; rbp is set with 4294967296
jne .L2