Dart Decision Making Statements

In this tutorial you will learn about the Dart Decision Making Statements and its application with practical example.

Dart decision making statements allow you to make a decision, based upon the result of a test condition. The decision making statements are also known as Conditional Statements.

What Is Decision Making Statements

So far, we have learned that all statements in a Dart program are executed sequentially (top to bottom) in the order in which they are written. This occurs until there is no jump statements or loop statements. But sometimes we may need to change the order of program execution depending on some specific conditions. Here comes the need of decision making structures that enable computer to decide set of statements to be executed depending upon some conditional choices. These statements are called as the decision making statements or Conditional Statements.

Dart Decision Making Statements

In Dart, we have rich set of Decision Making Statement that enable computer to decide which block of code to be execute based on some conditional choices. Decision making statement statements is also referred to as selection statements. Decision making statement evaluates single or multiple test expressions which results in “TRUE” or “FALSE”. The outcome of the test expression/condition helps to determine which block of statement(s) to executed if the condition is “TRUE” or “FALSE” otherwise. It is to be noted that Dart language assumes any non-zero or non-null value as true and if zero or null, treated as false.

Types of Decision Making Statements

In Dart, we have following types of decision making statements –

dart-decision-making-statements-types-chart

Dart If Statement

If statement allows a block of code to be executed only when a specified condition is true. An if statement evaluates a boolean expression followed by one or more statements. The given boolean expression results in a boolean value that can only be either true or false.

Syntax:-

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 execution is skipped from if body.

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.

Syntax:-

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.

Dart If Else If Statement

When we want to add multiple condition checks in single if else statement then by using if else-if else statement we can easily add multiple conditions. In Java, if..else..if statement allows us add alternative set of test conditions in if..else statement using else-if and single else statements for if condition. In such way if..else..if statement is used to select one among several blocks of code to be executed.

Syntax:-

Dart Switch Case Statement

In Dart, switch case statement is simplified form of the Nested if else statement , it helps to avoid long chain of if..else if..else statements. A switch case statement evaluates an expression against multiple cases in order to identify the block of code to be executed.

Syntax:-

In this tutorial we have learn about the Dart Decision Making Statements and its application with practical example. I hope you will like this tutorial.