IF Statement
Definition:
- It is one of the most powerful
decision-making conditional statement.
- IF Statement is always used with
condition where condition is checked before executing the body of loop.
Syntax:
The syntax of IF Statement in C-Language
if(Test Condition)
{
//Statement(S) will
execute if test condition is true
}
How IF Statement Works:
- The IF Statement checked the Test
Condition which is inside parenthesis ().
- If the Test Condition is checked as
true then only statement (s) inside the body of IF Statement will execute.
- This process will continue until the
Test Condition becomes false.
- If the Test Condition is checked as false then IF Statement gets terminated.
Illustration of IF Statement:
CASE-1: Test Condition is True
int a = 4;
{
//Statement(s) inside
the body of IF Statement loop
}
//Statement(s)
outside the body of IF Statement loop
CASE-2: Test Condition is False
int a = 4;
{
//Statement(s) inside the body of IF Statement loop
}
//Statement(s) outside the body of IF Statement loop
Program: Write a C program to illustrate IF Statement
#include<stdio.h>
int main()
{
int age = 15;
if(age>18)
{
printf(“Your age is less than 18”);
}
Printf(“I am not inside the IF Loop body”);
}
I am not inside the IF Loop body
Application:
It is mostly used in the case where we need to perform the different
operations for the different conditions.
1 Comments
Easy concept 👍
ReplyDeleteWelcome Dear Reader, I am very glad to help you | keep visiting my blog... Thanks !