List data = [1, 2, 3];
data.forEach((value) {
if (value == 2) {
// how to stop?
}
print(value);
});
Run Code Online (Sandbox Code Playgroud)
我尝试过return false;在jQuery中运行,但它在Dart中不起作用.有办法吗?
我想在 for 循环执行完成后中断 forEach 循环。
void main() {
var id = [1, 2, 3, 4, 5];
id.asMap().forEach((index, number) {
print('ForEach loop');
for (int i = 0; i < 1; i++) {
print("for loop");
}
});
}
Run Code Online (Sandbox Code Playgroud)