Nested if Statement
This type of statement checks the condition and if it is true then the if statement inside it checks its condition and if it is true then the statements are executed otherwise else statement is executed.
Syntax:
if ( condition1 ){
if ( condition2 ){
// Body of if
}
else {
// Body of else
}
}
Illustration with Image:
Example:
void main()
{
int gfg = 10;
if (gfg > 9) {
gfg++;
if (gfg < 10) {
print("Condition 2 is true");
}
else {
print("All the conditions are false");
}
}
}
Output:
All the conditions are false
Try code of if-else with Operator:
void main() {
int x = 5;
int y = 7;
if((++x > y--) && (++x < ++y)){
print("Condition true");
}
else {
print("Condition false");
}
print(x);
print(y);
}
Output:
Condition false
6
6
Dart Programming – If Else Statement (if , if..else, Nested if, if-else-if)
Decision-making statements are those statements that allow the programmers to decide which statement should run in different conditions.
There are four ways to achieve this:
- if Statement
- if-else Statement
- else-if Ladder
- Nested if Statement
Contact Us