Conditional execution — if statement
Lesson#10
Conditional execution means execution of block of statement is based on a condition. If a condition comes true then certain statements are executed. It is achieved in dart with the help of if statement and switch statements.
Syntax of if statement is:
if (condition)
statement1;
[else
statement2;]
Note that brackets in the syntax means optional part.
Condition is a logical expression (that returns either true or false). If condition is true then statement1 is executed otherwise statement2 is executed.
Example:
void main() {
var num = 5;
if (num < 10)
print("Less than 10!");
}
// Prints "Less than 10!" on screen
Relational operators in dart are <, >, ==, !=, <=, >=
Multiple conditions can be combined using the logical operators. Logical operators in dart are && (for AND), || (for OR), and ! (for NOT).