![Sindhu Chowdary](https://www.crazyengineers.com/img/avatar.jpg)
Sindhu Chowdary
Member • Jan 18, 2014
Post increment in a loop
I am reading about what happens when a post increment is present in a loop and I came across this.Can anyone explain me the below code?
A simple loop like
i = 0;
while (a[i++] != 0)
{
...
}
has to be executed as
loop:
temp = i; /* save the value of the operand */
i = temp + 1; /* increment the operand */
if (a[temp] == 0) /* use the saved value */
goto no_loop;
...
goto loop;
no_loop:
or
loop:
temp = a; /* use the value of the operand */
i = i + 1; /* increment the operand */
if (temp == 0)
goto no_loop;
...
goto loop;
no_loop:
A simple loop like
i = 0;
while (a[i++] != 0)
{
...
}
has to be executed as
loop:
temp = i; /* save the value of the operand */
i = temp + 1; /* increment the operand */
if (a[temp] == 0) /* use the saved value */
goto no_loop;
...
goto loop;
no_loop:
or
loop:
temp = a; /* use the value of the operand */
i = i + 1; /* increment the operand */
if (temp == 0)
goto no_loop;
...
goto loop;
no_loop: