can any one write a c program in which both the if and else statements should execute???

Welcome aboard. If you have specific problems when trying to do a program...please post the source code here along with what you think may be wrong. Also post the errors you get, so we can take a look and help you. We are not in the business of doing your home-work for you! You must TRY/show some effort!!

Comments
Getting tired of this lame message -- especially for someone that has many posts

can any one write a c program in which both the if and else statements should execute???

Yes I can. Can you?

really? can you?
hmm... never thought about that...

but from what i know, when the if clause is true the esle clause doesn't get to be tested, so it won't execute and when if cluase is false, then it will be executed the else clause.

can an expression be true and false in the same time?

where you jokin' ?

no. Nowhere does it say it has to be during the same execution run of the block ;)

for (int i=0; i<2; i++) {
    if (i == 0) {
        // do something
    } else {
        // do something else
    }
}

hey if you r seriously telling this please let me know how u can do it coz i never heard of the logic that can execute both the if and else conditions in the same program......

hey if you r seriously telling this please let me know how u can do it coz i never heard of the logic that can execute both the if and else conditions in the same program......

if( !printf( "I am the IF\n" ) )
 	printf( "I am the IF\n");
   else
	printf( "I am the ELSE\n" );
if( !printf( "I am the IF\n" ) )
 	printf( "I am the IF\n");
   else
	printf( "I am the ELSE\n" );

here the if condition is not executing ... only the statement after the if deywor is getting displayed...
the if conition is false always and so the condition of the else part is being displayed!!!!

I THINK SO!!!:S

I THINK SO!!!

I think you are right.

Although the use of goto is discouraged, one can use it over here just as an answer to this problem.

here the if condition is not executing ... only the statement after the if deywor is getting displayed...
the if conition is false always and so the condition of the else part is being displayed!!!!
I THINK SO!!!:S

Can something be here and there at the same time? Can something be white and black at the same time? YES, but the answer will involve "trick" and twisting of the "reality of the expected".
You can go to a "magic spectacle" and enjoy the show or get out of it feeling "cheated". After all we all know that's not real, or isn't ?. Depends of the point of view.

Jwenting gave you a view. You cataloged as cheap.
I gave you another view. You objected in a base of technicality.

I will give you two more:

if ( 1 )
	{
		printf( "I am if\n" );
	}
	else;
	{
		printf( "I am else\n" );
        }
if (1)
	{
		loop:printf("TRUE\n");
		goto loop2;
	}
	else
	{
		goto loop;
		loop2: printf("FALSE\n");
	}

Now, what value is in it? I would say, as little as the OP question.
Perhaps it will teach you not to forget a ; in the wrong place, or maybe not to abuse a GOTO.
Still not happy?
Well, I'll say to you a modification of the old cliché: You can't bake the pie and eat it at the same time. ;)

Comments
Ditto

u hav got it all wrong ....
the first one doesnt work too.... and about the second one...
when the condition in if part is 1 it means that it is always true and so only the if part will execute and the else part is left as it is.... so ur concept is wrong again ....
SORRYyo:icon_evil:

u hav got it all wrong ....
the first one doesnt work too....

Yes it does. Did you even try it? This piece from the code (#1) is very important:

else[B];[/B]

The semicolon means that there is no else statement, and thus the code in brackets is always executed. It has nothing to do with the IF-statement, it just looks that way because it is in brackets and directly below the word 'else'.

You can't bake the pie and eat it at the same time. ;)

I disagree. If your oven has a conveyor belt build in to it, it would be possible to eat the first part of the pie, while the other part is still in the oven being baked. :)

regards Niek

I disagree. If your oven has a conveyor belt build in to it, it would be possible to eat the first part of the pie, while the other part is still in the oven being baked. :)

I dare you to try it! :icon_twisted:

if( !printf( "I am the IF\n" ) )
 	printf( "I am the IF\n");
   else
	printf( "I am the ELSE\n" );

didnt got ne more prgms to get the if and else part executed at the same time...
give it up .. it can never be done....


can u ever play football and vollyball at the same time????

maradona was an exception:P

didnt got ne more prgms to get the if and else part executed at the same time...
give it up .. it can never be done....


can u ever play football and vollyball at the same time????

maradona was an exception:P

What???? You need to read this -- it's part of the site rules. In other words, this post breaks the site rules. In fact, many of your posts do.

This article has been dead for over six months. Start a new discussion instead.