M
mohdalibaig
why does this loop exectue once?
for( ; 0 ; )
printf("WHY"); ???
for( ; 0 ; )
printf("WHY"); ???
why does this loop exectue once?
for( ; 0 ; )
printf("WHY"); ???
why does this loop exectue once?
for( ; 0 ; )
printf("WHY"); ???
why does this loop exectue once?
for( ; 0 ; )
printf("WHY"); ???
why does this loop exectue once?
for( ; 0 ; )
printf("WHY"); ???
why does this loop exectue once?
for( ; 0 ; )
printf("WHY"); ???
Yes it should. Either the compiler is bugged - apparently one was releasedBeej Jorgensen said:It shouldn't--the "0" expression should be evaluated before the
printf().
why does this loop exectue once?
for( ; 0 ; )
printf("WHY"); ???
It doesn't. I expect your /actual source/ has a
mistake in it. I'm going to take a wild guess
that you had a semicolon after the for's closing
bracket.
Show us a complete compilable program that exhibits the problem.
Don't paraphrase it, don't re-type it, copy-and-paste it. You should
be able to write a complete program in less than a dozen lines.
And let us know what compiler you're using, and what version. I seem
to recall that some old compiler has a bug with that particular
construct.
Why did it occur to you to write "for( ; 0 ; )" in the first place?
If you want to do nothing, there are easier ways to do it. The only
reason I can think of to write "for( ; 0 ; )" is to deliberately
trigger the above-mentioned compiler bug.
This has come up before, and the answer seems to be a bug in the
Borland compiler. I take it you are using a Borland compiler?
Hope that helps.
Paul.
#include<conio.h>
#include<stdio.h>
void main(void)
{
clrscr();
for(int i=0; 0; i++)
printf("Why");
getch();
}
the output on my screen is
Why
That's not a C program.
#include<stdio.h>
int main(void)
{
int i;
for( i=0; 0; i++ )
printf("Why");
return 0;
}
Not for me. Bet that advice you got about buggy Borland compilers is
correct.
Thanks. Which compiler do you have?
[signature snipped]Show us a complete compilable program that exhibits the problem.
Don't paraphrase it, don't re-type it, copy-and-paste it. You should
be able to write a complete program in less than a dozen lines.
And let us know what compiler you're using, and what version. I seem
to recall that some old compiler has a bug with that particular
construct.
Why did it occur to you to write "for( ; 0 ; )" in the first place?
If you want to do nothing, there are easier ways to do it. The only
reason I can think of to write "for( ; 0 ; )" is to deliberately
trigger the above-mentioned compiler bug.
i am writing the complete code here
#include<conio.h>
#include<stdio.h>
void main(void)
{
clrscr();
for(int i=0; 0; i++)
printf("Why");
getch();
}
Although complier is showing a warning. Unreachable code. i am using
Borland compiler version 3.0
.... snip ...
i am writing the complete code here
#include<conio.h>
#include<stdio.h>
void main(void)
{
clrscr();
for(int i=0; 0; i++)
printf("Why");
getch();
}
the output on my screen is
Why
Although complier is showing a warning on printf line . Unreachable
code...
why does this loop exectue once?
for( ; 0 ; )
printf("WHY"); ???
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.