CrazyEngineers
  • 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:
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Anoop Kumar

    MemberJan 18, 2014

    Post increment mean calculate the value and then increament.
    This will be

    loop:
    temp = i; /* save the value of the operand */
    i = temp + 1; /* increment the operand */
    if (a[temp] == 0) /* use the saved value */
    i = temp + 1; /* post increament */
    goto no_loop;
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register