If Statement and Nested if Statement
If statement is used to execute when a statement or a block of statement only if the condition is fulfilled or true.
Syntax
For One Statement:-
if(condition/expression)
statement;
For more than one Statement:-
if(condition/expression)
{
Blocks of statement;
}
OR
if(condition/statement):
Blocks of statements;
endif;
Sample Program
Output
Nested if Statement
We can make nesting statement by nesting the if statement. It means when we insert a second if statement inside an if statement, we call it nested if statement or nesting the if statement.
Sample Program
Output
To know more about If Statement and Nested if Statement Click here – If Statement and Nested if Statement
if else and Nested if else Statement.
A statement executes code if if_condition is true and executes another code if if_condition is false.
Syntax
if(condition/expression)
{
Statement1;
}
else echo “Statement2”;
Example – when Condition is True then, if_condition executes. See Below
Sample Program
Output
when Condition is False then, else_condition executes. See Below
Sample Program
Output
Nested if else Statement
we insert a second if_else statement inside an if_else statement, we call it nested _if_else statement.
syntax
if(condition/expression)
{
if(condition/expression)
{
Statement1;
}
else echo “Statement2”;
}
else echo “Statement2”;
Sample Program
In the above program, The first Condition is true, then it enters in 2nd condition to check and when the 2nd condition is true then it prints that statement and skips other else statements. See the Output below:
Click Here For Next Part – Difference between Single Equal, Double Equal and, Triple Equal in PHP
- What is On-Page Optimization and Off-page Optimization - March 14, 2024
- [SOLVED] Flutter : PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null) - December 7, 2021
- [Solved] Flutter : Error: The getter ‘subhead’ isn’t defined for the class ‘TextTheme’ from package:flutter/src/material/text_theme.dart’ – searchable_dropdown - December 6, 2021