How to use DART control flow statements
In this article we will discuss about different type control flow statements in DART.
Control flow statements
The statements which allow us to control the flow of our program, rather than execution every one of code in the order it appears in the program. Some of control flow statements is given below.
- Break statement
The break statement is used when we want to exit out from any for, while , do-while loops, or any statements like switch etc.
Example of break statement
void main() {
for(int i=1;i<=3;i++){
print(i);
break; //here only single value is printed because break statements is exit out from it's loop.
}
}
|
Output:
-
Continue statement
The continue statement is similar to break, it is also used in for, while, do-while, it exit from the current iteration of the loop and execution will start from beginning of the loop.
Example of continue statement
void main() {
var i;
for(i=1;i<=3;i++){
print(i);
continue;
i++; //skip that step.
}
}
|
Output:
Example of assert statements
void main() {
bool a = true;
assert(a!=null);
print("If you use assert you also compare two instance variables");
}
|
Output:
Ask Your Question
Got a programming related question? You may want to post your question here