else…if Ladder
This type of statement simply checks the condition and if it is true the statements within it are executed but if it is not then other if conditions are checked, if they are true then they are executed, and if not then the other if conditions are checked. This process is continued until the ladder is completed.
Syntax:
if ( condition1 ){
// body of if
}
else if ( condition2 ){
// body of if
}
.
.
.
else {
// statement
}
Illustration with Image:
Example:
void main()
{
int gfg = 10;
if (gfg < 9) {
print("Condition 1 is true");
gfg++;
}
else if (gfg < 10) {
print("Condition 2 is true");
}
else if (gfg >= 10) {
print("Condition 3 is true");
}
else if (++gfg > 11) {
print("Condition 4 is true");
}
else {
print("All the conditions are false");
}
}
Output:
Condition 3 is true
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