Loops in DART
In this article, I am going to explain how to use loops in DART.
Looping In DART
Dart provide different looping mechanisms which allow us to execute a block of code repeatedly until a certain condition is met.
Example of for loop
void main() {
for(int i=1;i<=5;i++){
print("${i}");
}
}
|
Output:
Example of for in loop
void main() {
var collection=[1,2,3,4,5];
for(var a in collection){
print(a);
}
}
|
Output: Same as above Example
Example of while loop
void main() {
int i=1;
while(i<=5 ){
print("${i}");
i++;
}
}
|
Output: same as above example
Example of do-while loop
void main() {
var i=1;
do{
print(i);
i++;
}
while(i<=5);
}
|
Output:
Ask Your Question
Got a programming related question? You may want to post your question here