If Statement
Blog Contents
Control Statements:
There are different types of control statements. It is also called as Flow control statements i.e, we can execute the block of program based on the conditions. There are different types of Flow Control Statements. They are
Decision Statement
1. If Statement.
2. If…else and if…else…if statements
3. nested if else statement
4. switch case
Looping Statements
1. for loop
2. while loop
3. do…while loop
4. Nested loop
Jump Statements
1. Break Statement
2. Continue statement
3. goto Statement
If Statement:
If statement is used in c to control the flow of program with conditional expression. If condition is true, then the block of statement will be executed
Syntax:
if( condition)
{
statement 1; // The block of statement which would be executed
statement 2; // when condition is true, then execute this block of statements
……
……
statement n;
}
If the condition is true, then the statement inside the body of “if” only executed. If the condition is false, then the statement inside the body of “if” will be skipped.
How it works:
Flow Chart:
Now, we can see the example with a program.
#include<stdio.h>
int main()
{
int a=5, b=8;
if(a<b) // if the condition is true then it will execute the if block statement
{ // if condition is false then it ends the program
printf(“The number a=%d is lessthan b= %d”, a,b);
}
return 0;
}
OUTPUT:
The number a=5 is lessthan b=8.
So now we discussed the If statement and the remaining flow control statements will be explain on the following documents. If you want to establish a good carrier then we need to have good knowledge on the basic language . This language is very useful to the Embedded Systems and to get more knowledge we need join in the top embedded training institutes in Bangalore and we are the Professional Training institute in Bangalore and we will focus on the good knowledge for the students.