Simple If Statement

The if is a powerful decision making statement and is used to control the flow of execution of statements. It is basically a two way decision statement and is used in conjunction with an expression. it takes the following form-

if ( test expression)

It allows the computer to evaluate the expression first and then, depending on whether the value of the expression ( relation or condition) is true or false, it transfers the control to a particular statement. This point of program has two paths to follow, one for the true condition and the other for the false condition.

The general form of if statement is –

if( test expression)

The ‘statement- block’ may be a single statement or a group of statements. If the test expression is true, the statement-block will be executed; otherwise the statement-block will be skipped and the execution will jump to the statement-x. Remember, when the condition is true both the statement-block and the statement-x are executed in sequence.

Below is the sample program to find if the inputted number is greater than 50 –


void main()
     int n;
     printf("Enter any Number \n");
              printf("%d is greater than 50 \n",n);
     printf("The program ends");

Also it is advised to make the block of the if statement even if one statement is to be executed for the ‘ if ‘ expression is true . It will make the language easy for you to understand.

yashan has written 69 articles

2 thoughts on “Simple If Statement

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>