Introduction to dart-control processes and other control processes If~else
If statement and optional Else statement, a simple if statement can be handled with the conditional operator (?:)
if{ you.bringRainCoat();}elseif{ you.wearJacket();}else{ car.putTopDown();}
For
Iterating using a For loop
varnew StringBuffer("Dart is fun");for (var05; i++) { message.write(‘!‘);}
Iterating over a iteration object using the foreach () method
List<String> names = ["Alice""Daphne""Elizabeth""Joanna"];names.forEach((name){ print(name);});
Use For~in to iterate through the list type and set type of the Iteration object
var collection = [012];for (varin collection) { print(x);}
While, Do~while
While loop, first judge the condition and then enter the loop.
while (!isDone()) { doSomething();}
Do~while cycle, first enter the cycle and then judge the condition
do { while (!atEndOfPage());
Break, continue
Stop a loop with break
while (true) { ifbreak; processIncomingRequest();}
Skip this cycle with continue
fori0;icandidates.length;i{ var candidate = candidates[i]; if (candidate.yearsExperince < 5) { continue; } candidate.interview();}
Switch, case
Switch is typically used for the comparison of integers, strings, and compile constants, and the objects must be of the same type, each case must end with a break
varCommand =' OPEN ';Switch(command) { Case ' CLOSED ': executeclosed (); Break; Case ' PENDING ': Executepending (); Break; Case ' approved ': Executeapproved (); Break; Case ' DENIED ': Executedenied (); Break; Case ' OPEN ': Executeopen (); Break;default: Executeunknown (); }
Can fail if case content is empty, or use continue to continue execution
var‘CLOSED‘;switch (command) { case‘CLOSED‘: executeClosed(); continue nowClosed;nowClosed: case‘NOW_CLOSED‘: executeNowClosed(); break;}
Assert
Use an Assert statement to disturb normal operation if the Boolean value is False, only in check mode
//确保变量非空assertnull);//确保值小于100assert100);//确保这是一个https URLassert(urlString.startsWith(‘https‘));
Comments
// 这是一行注释/* 这是一大段注释*/
private variables and functions
There are no public, protected, and private keywords in dart syntax, so you can declare a private variable or function simply by adding "_" in front of the identifier.
Add content at irregular intervals
Getting Started with dart-control processes and other