Getting Started with dart-control processes and other

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.