Flutter跳出多层循环

flutter - Is there a Goto function in Dart? - Stack Overflow

void main() {
outerloop: // This is the label name

for (var i = 0; i < 3; i++) {
  print("Outerloop:${i}");

  for (var j = 0; j < 5; j++) { 
     if (j == 3){ 
        continue outerloop; 
     } 
     print("Innerloop:${j}"); 
  } 
}
}

out label要紧挨for,放到外层for的上面。
label和for之间,不能有其他语句,但是可以有空行。

猜你喜欢

转载自blog.csdn.net/gaoyp/article/details/120328646