if Statement

Default Image

f is the decision-making
statement to check either condition is true or not. If condition is then
the following code that is under the block of if will show output or
further processing will be continue and if the given condition is false,
then following statements will be ignored and program moved further.
Sample syntax of if statement is given below:

statement-1;

if(condition)

statement-2;

statement-3;


In above example statement-1 is the
simple statement that is executing as per schedule or flow of program.
After it next statement contains if keyword, statement-2 will be
executed if the condition is true. In case condition is false then
statement-2 will be skipped and statement-3 will be executed.


In a case if you want to execute more
then one condition under if statement then we need to make a block
enclosed in curly braces. This group enclosed in braces is called
compound statement. Example of compound statement is given below:


statement-1;

if(condition)

{

statement-2;

statement-3;

statement-4;

}

statement-5;


In this above example after execution of
statement-1 the if condition will be checked in case it is true the
statements from 2 to 4 will be executed and the 5 in other hand the
condition is false then after statement-1, statement-5 will executed.


 









#include

#include

void main()

{

int a;

clrscr();

cout<>a;

if(a>50)

cout<<“Number is greater than 50”;

cout<<“End of execution”;

getch();

}
Enter a number :45

End of execution

You can download simple if programme source code given above from github.com

Read Count: 3 times

Comments

No comments yet.

Leave a Comment