flutter中dart循环

for循环

for (int i = 0; i <= 10; i++) {
    print(i);
  }

for in

for (int i = 0; i <= 10; i++) {
    print(i);
  }

while

List people = ['tom', 'ant', 'jeson'];
  int i = 0;
  while (i < people.length) {
  print(people[i]);
    i++;
   }

do whild

List people = ['tom', 'ant', 'jeson'];
int i = 0;
 do {
   print(people[i]);
   i++;
 } while (i < people.length);

break关键字

 for (int i = 0; i <= 10; i++) {
    if (i == 4) {
      break;
    }
    print(i);
  }

指定停止某个循环

outLoop:
  for (int i = 0; i < 3; i++) {
    innerLoop:
    for (int j = 0; j < 3; j++) {
      if (i == 2) {
        break innerLoop;
      }
      print('$i $j');
    }
  }

continue 停止本次循环

for (int i = 0; i < 3; i++) {
    if (i == 1) {
      continue;
    }
    print(i);
  }
发布了96 篇原创文章 · 获赞 15 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_35958891/article/details/103526988