searchsanjaysharma
asked on
How does conditional part work in for loop.
Case 1:
main()
{
int a=0;
for(;a;)
{
printf("Hello");
}
}
Output: /*It doesn't print Hello*/
Case 2:
main()
{
for(;0;)
{
printf("Hello");
}
}
/*prints hello for one time*/
Why this kind of output comes in Turbo C++
main()
{
int a=0;
for(;a;)
{
printf("Hello");
}
}
Output: /*It doesn't print Hello*/
Case 2:
main()
{
for(;0;)
{
printf("Hello");
}
}
/*prints hello for one time*/
Why this kind of output comes in Turbo C++
Either you or Turbo C++ must have done something wrong.
ASKER
Hi ozo,
You may try with your expertise and check , since i found this an exception, hence i posted that.
You may try with your expertise and check , since i found this an exception, hence i posted that.
Neither case should print Hello at all.
ASKER
Yes, its there, but when u execute it doesnt happen.
What is where and what doesn't happen when u execute what?
Try compiling to assembler and see what the output is - that should give you some idea of what it is doing.
Can confirm this does not happen in other compilers.
Can confirm this does not happen in other compilers.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> Why this kind of output comes in Turbo C++
There are only two possible reasons:
1. The code example you've provided isn't actually what you're building and running
2. Your compiler is defective
I very much doubt it's number 2 so I have to conclude that it's number 1.
Put simply, I concur with ozo.
Please copy and paste, verbatim, the code you are building.
>> Can confirm this does not happen in other compilers.
Phew! :)
There are only two possible reasons:
1. The code example you've provided isn't actually what you're building and running
2. Your compiler is defective
I very much doubt it's number 2 so I have to conclude that it's number 1.
Put simply, I concur with ozo.
Please copy and paste, verbatim, the code you are building.
>> Can confirm this does not happen in other compilers.
Phew! :)
i once had a semicolon ; after the for statement.
and some_code() function was called once.
it took me some time to find out what was wrong ...
Sara
for(;<some_lengthy_condition_which_was_false>;);
{
some_code();
}
and some_code() function was called once.
it took me some time to find out what was wrong ...
Sara
ASKER
tx