S
somenath
Hi All,
I have doubt regarding how compiler understands about while loop. For
example the bellow mentioned code produce the output as mentioned
bellow.
#include<stdio.h>
int main(void)
{
int i =10 ;
goto label;
while(--i > 0)
{
label:
printf("\n Value of i = %d \n",i);
}
return 0;
}
Value of i = 10
I/O:
I/O: Value of i = 9
I/O:
I/O: Value of i = 8
I/O:
I/O: Value of i = 7
I/O:
I/O: Value of i = 6
I/O:
I/O: Value of i = 5
I/O:
I/O: Value of i = 4
I/O:
I/O: Value of i = 3
I/O:
I/O: Value of i = 2
I/O:
I/O: Value of i = 1
My understanding of the behavior is when the execution encounter goto
statement it jumps to label: and when it find that it is inside while
loop it goes back to while(--i > 0) and execute the loop.
Is my understanding correct ?
If it is correct then my question is how "c" compiler understand that
it is inside loop?
Please help .
Regards,
Somenath
I have doubt regarding how compiler understands about while loop. For
example the bellow mentioned code produce the output as mentioned
bellow.
#include<stdio.h>
int main(void)
{
int i =10 ;
goto label;
while(--i > 0)
{
label:
printf("\n Value of i = %d \n",i);
}
return 0;
}
Value of i = 10
I/O:
I/O: Value of i = 9
I/O:
I/O: Value of i = 8
I/O:
I/O: Value of i = 7
I/O:
I/O: Value of i = 6
I/O:
I/O: Value of i = 5
I/O:
I/O: Value of i = 4
I/O:
I/O: Value of i = 3
I/O:
I/O: Value of i = 2
I/O:
I/O: Value of i = 1
My understanding of the behavior is when the execution encounter goto
statement it jumps to label: and when it find that it is inside while
loop it goes back to while(--i > 0) and execute the loop.
Is my understanding correct ?
If it is correct then my question is how "c" compiler understand that
it is inside loop?
Please help .
Regards,
Somenath