The IF statement
The C language uses the keyword if to implement the decision control instruction.
The general form of IF statement is as follows;
if ( condition )
execute this statement ;
The condition following the keyword if is always enclosed within a pair of parentheses. If the condition is true then the given statement is executed.If the condition is not true then the statement is not executed; instead the program skips past it. To express conditions in C we use conditional operators.
Expression | Meaning |
x == y | x is equal to y |
x != y | x is not equal to y |
x <> | x is less than y |
x > y | x is greater than y |
x <= y | x is less than or equal to y |
x >= y | x is greater than or equal to y |
Lets consider a sample program;
/* The IF statement */
main( )
{
int num ;
printf ( "Enter a number less than 50 " ) ;
scanf ( "%d", &num ) ;
if ( num <= 50 )
printf ( "You are fail" ) ;
}
On execution,if you enter a number less than equal to 50 you will get the message on the screen but if the number if greater than 50 you wont get any output.
There may be more than one IF statement in a program as per requiremant.
Comments