How to stop Dart's .forEach()?

后端 未结 9 1744
星月不相逢
星月不相逢 2020-12-05 09:02
List data = [1, 2, 3];
data.forEach((value) {
  if (value == 2) {
    // how to stop?
  }
  print(value);
});
9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 09:49

    Dart does not support non-local returns, so returning from a callback won't break the loop. The reason it works in jQuery is that each() checks the value returned by the callback. Dart forEach callback returns void.

    http://docs.jquery.com/Core/each

提交回复
热议问题