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) { statement-block; } statement-x;
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 –
#include<stdio.h> void main() { int n; printf("Enter any Number \n"); scanf("%d",&n); if(n>50) { printf("%d is greater than 50 \n",n); } printf("The program ends"); getch(); }
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.
No Pain no gain
Are simple if statement and simple if construct same???
What a wonderful article! I spend a few minutes on reading, and I’m really so excited by the advice I received, by the manner of writing it reminded
me https://essayservice.com/blog/explanatory-essay. It’s truly hard
to find something invaluable on that topic. However, because
really just a special style is in his writings, this author appears to be considered a professional.
I’m going to sign up to his books that are new, simply not to skip any such thing.
This informative article works its reading.