![]() |
How To Use If Else Statement With Examples |
How To Use If Else Statement With Examples
If Statement: The ability to regulate the flow of your program, rental it builds choices on what code to execute, is effective to the applied scientist.
The if statement permits you to regulate if a program enters a part of code or is not supported whether or not a given condition is true or false.
An if statement is the most important statement in the c language.it can be used to decide control flow in the c program. condition is true than if the statement executes the program.
Important Same Others If Else Statement
👉C++ If-Else Statement
👉Java If-Else Statement
👉Python If-Else Statement
if statement to examine a user-entered positive identification, your program will decide whether or not a user is allowed access to the program.
if(age>=18)
Here if conditions are true then the statement is executed otherwise the program is executed but the output does not show in your output screen.
Syntax of if Statement
if(condition)
{
//Statement
}
if(condition)
{
//Statement
}
How To Use if Statement in C?
#include <stdio.h>
int main()
{
int age=18;
if(age>=18)
{
print("you can drive a bike");
}
}
*****OUTPUT*****
you can drive a bike
#include <stdio.h>
int main()
{
int age=18;
if(age>=18)
{
print("you can drive a bike");
}
}
*****OUTPUT*****
you can drive a bike
How To if from user input Statement in C?
#include <stdio.h>
int main()
{
int age;
printf("Please Enter Your Age:");
scanf("%d",&age);
if(age>=18)
{
print("you can drive a bike");
}
}
*****OUTPUT*****
Please Enter Your Age:21
you can drive a bike
#include <stdio.h>
int main()
{
int age;
printf("Please Enter Your Age:");
scanf("%d",&age);
if(age>=18)
{
print("you can drive a bike");
}
}
*****OUTPUT*****
Please Enter Your Age:21
you can drive a bike
Syntax of if-else Statement
if(condition)
{
//Statement
}
else
{
//Statement
}
if(condition)
{
//Statement
}
else
{
//Statement
}
How To Use if-else Statement in C?
#include <stdio.h>
int main()
{
int age=17;
if(age>=18)
{
print("You can Drive Bike");
}
else
{
print("You can not Drive Bike");
}
}
*****OUTPUT*****
You can not Drive Bike
#include <stdio.h>
int main()
{
int age=17;
if(age>=18)
{
print("You can Drive Bike");
}
else
{
print("You can not Drive Bike");
}
}
*****OUTPUT*****
You can not Drive Bike
How To if-else from user input Statement
#include <stdio.h>
int main()
{
int age;
printf("Enter your age:");
scanf("%d",&age);
if(age>=18)
{
print("You can Drive Bike");
}
else
{
print("You can not Drive Bike");
}
}
*****OUTPUT*****
Please Enter Your Age:15
You can not Drive Bike
#include <stdio.h>
int main()
{
int age;
printf("Enter your age:");
scanf("%d",&age);
if(age>=18)
{
print("You can Drive Bike");
}
else
{
print("You can not Drive Bike");
}
}
*****OUTPUT*****
Please Enter Your Age:15
You can not Drive Bike
if-else-if statement: A if-else-if part of if conditional statement that executes only one condition at a time.it is all conditions are false then else part is executed.
Syntax of if-else Statement
if(condition)
{
//Statement 1;
}
else if()
{
//Statement 2;
}
else if()
{
statement 3;
}
else
{
statement 4;
}
if(condition)
{
//Statement 1;
}
else if()
{
//Statement 2;
}
else if()
{
statement 3;
}
else
{
statement 4;
}
How To Use if-else-if Statement in C?
#include <stdio.h>
int main()
{
int age=18;
if(age<=14)
{
print("You are Kid");
}
else if(age<=18)
{
print("You can Drive Bike");
}
else
{
print("You can not Drive Bike");
}
}
*****OUTPUT*****
You can Drive Bike
#include <stdio.h>
int main()
{
int age=18;
if(age<=14)
{
print("You are Kid");
}
else if(age<=18)
{
print("You can Drive Bike");
}
else
{
print("You can not Drive Bike");
}
}
*****OUTPUT*****
You can Drive Bike
How To if-else from user input Statement
#include <stdio.h>
int main()
{
int age;
printf("Enter your age:");
scanf("%d",&age);
if(age<=14)
{
print("You are Kid");
}
else if(age<=18)
{
print("You can Drive Bike");
}
else
{
print("You can not Drive Bike");
}
}
*****OUTPUT*****
Please Enter Your Age:13
You are Kid
#include <stdio.h>
int main()
{
int age;
printf("Enter your age:");
scanf("%d",&age);
if(age<=14)
{
print("You are Kid");
}
else if(age<=18)
{
print("You can Drive Bike");
}
else
{
print("You can not Drive Bike");
}
}
*****OUTPUT*****
Please Enter Your Age:13
You are Kid
Nested if statement: Nested if statement means one inside another so one if inside another if is called nested if statement.
Syntax of Nested if Statement
if(condition)
{
if(condition)
{
//Statement;
}
}
if(condition)
{
if(condition)
{
//Statement;
}
}
How To Use Nested from Statement in C?
#include <stdio.h>
int main()
{
int num=100;
if(num>25)
{
if(num<200)
{
printf(" 200 number is grater than 100");
}
}
}
*****OUTPUT*****
200 number is greater than 100
#include <stdio.h>
int main()
{
int num=100;
if(num>25)
{
if(num<200)
{
printf(" 200 number is grater than 100");
}
}
}
*****OUTPUT*****
200 number is greater than 100