- Dart Programming Tutorial
- Dart Programming - Home
- Dart Programming - Overview
- Dart Programming - Environment
- Dart Programming - Syntax
- Dart Programming - Data Types
- Dart Programming - Variables
- Dart Programming - Operators
- Dart Programming - Loops
- Dart Programming - Decision Making
- Dart Programming - Numbers
- Dart Programming - String
- Dart Programming - Boolean
- Dart Programming - Lists
- Dart Programming - Lists
- Dart Programming - Map
- Dart Programming - Symbol
- Dart Programming - Runes
- Dart Programming - Enumeration
- Dart Programming - Functions
- Dart Programming - Interfaces
- Dart Programming - Classes
- Dart Programming - Object
- Dart Programming - Collection
- Dart Programming - Generics
- Dart Programming - Packages
- Dart Programming - Exceptions
- Dart Programming - Debugging
- Dart Programming - Typedef
- Dart Programming - Libraries
- Dart Programming - Async
- Dart Programming - Concurrency
- Dart Programming - Unit Testing
- Dart Programming - HTML DOM
- Dart Programming Useful Resources
- Dart Programming - Quick Guide
- Dart Programming - Resources
- Dart Programming - Discussion
Dart Programming - If Else Statement
The else…if ladder is useful to test multiple conditions. Following is the syntax of the same.
if (boolean_expression1) { //statements if the expression1 evaluates to true } else if (boolean_expression2) { //statements if the expression2 evaluates to true } else { //statements if both expression1 and expression2 result to false }
When using if…else statements, there are a few points to keep in mind.
An if can have zero or one else's and it must come after any else…if's.
An if can have zero to many else…if's and they must come before the else.
Once an else…if succeeds, none of the remaining else…if's or else's will be tested.
Example - else…if ladder
The following program code checks whether a given value is positive, negative, or zero.
void main() { var num = 2; if(num > 0) { print("${num} is positive"); } else if(num < 0) { print("${num} is negative"); } else { print("${num} is neither positive nor negative"); } }
The following output is displayed on successful execution of the above code.
2 is positive
dart_programming_decision_making.htm
Advertisements