Dart Programming - Decision Making



A conditional/decision-making construct evaluates a condition before the instructions are executed.

Decision Making

Conditional Constructs

Conditional constructs in Dart are classified in the following table.

Sr.No Statement & Description
1 if statement

An if statement consists of a Boolean expression followed by one or more statements.

2 If...Else Statement

An if can be followed by an optional else block. The else block will execute if the Boolean expression tested by the if block evaluates to false.

3 elseif Ladder

The elseif ladder is useful to test multiple conditions. Following is the syntax of the same.

4 switchcase Statement

The switch statement evaluates an expression, matches the expressions value to a case clause and executes the statements associated with that case.

Usage of Conditional Construct

The following example shows how you can use the continue statement in Dart −

Example

The following example shows how you can use the if statement in Dart.

void main() { 
   var  num=-5; 
   if (num<0) { 
      print("number is negative"); 
   }    
}

The above example will print number is negative as the condition specified by the if block is true.

number is negative 
Advertisements