In this tutorial you will learn about the Dart if else Statement and its application with practical example.
Dart if else Statement
In Dart, when we want to execute a block of code when if condition is true and another block of code when if condition is false, In such a case we use if…else statement.
Dart If…else Statement Flow Diagram
Syntax:-
1 2 3 4 5 |
if(condition){ // statements } else { // statements } |
Here, Condition is a Boolean expression that results in either True or False, if it results in True then statements inside if body are executed, if it results in False then statements inside else body are executed.
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
void main() { var a = 10; var b = 20; print("W3Adda - Dart If else Statement"); if(a > b){ print("a is greater than b"); } else { print("b is greater than a"); } } |
Output:-