- 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 - List Operations
- 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
Selected Reading
Dart Programming - break Statement
The break statement is used to take the control out of a construct. Using break in a loop causes the program to exit the loop. Following is an example of the break statement.
Syntax
Following is the syntax for the break statement in a while Loop.
while (expression) {
Statement(s) to be executed;
break;
}
Usage of break Statement
Example
void main() {
var i = 1;
while(i<=10) {
if (i % 5 == 0) {
print("The first multiple of 5 between 1 and 10 is : ${i}");
break ;
//exit the loop if the first multiple is found
}
i++;
}
}
Output
The above code prints the first multiple of 5 for the range of numbers within 1 to 10.
If a number is found to be divisible by 5, the if construct forces the control to exit the loop using the break statement. The following output is displayed on successful execution of the above code.
The first multiple of 5 between 1 and 10 is: 5
dart_programming_loops.htm
Advertisements