流程控制

if else

bool isPrint = true;
if (isPrint) {
  print('hello');
}

for

for (var i = 0; i < 5; i++) {
  print(i);
}

while

bool isDone = false;
while(!isDone) {
  print('is not done');
  isDone = true;
}

do while

bool isRunning = true;
do {
  print('is running');
  isRunning = false;
} while (isRunning);

switch case

String name = 'cat';
switch (name) {
  case 'cat':
    print('cat');
    break;
  default:
    print('not find');
}

break

num i = 1;
while(true) {
  print('${i} - run');
  i++;
  if(i == 5) {
    break;
  }
}

continue

for (var i = 0; i < 5; i++) {
  if (i < 3) {
    continue;
  }
  print(i);
}

continue 指定位置

String command = "close";
switch (command) {
  case "open":
    print("open");
    break;
  case "close":
    print("close");
    continue doClear;
  case "close2":
    print("close2");
    continue doClear;

  doClear:
  case "doClose":
    print("doClose");
    break;

  default:
    print("other");
}
Last Updated:
Contributors: ducafecat