我想在 Dart 中創建一個腳本,用于檢測 OutputBool2 串列中何時在下一個索引中有一個“假”和一個“真”
我創建了這個腳本,但它似乎不起作用:
List OutputIndex2 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23];
List OutpuBool2 = [false, false, false, false, false, false, false, true, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false];
for (int j in OutputIndex2.sublist(0, OutputList2.length - 1)) {
print(j);
if (OutputBool2[j] == false && OutputList2[j 1] == true) {
print(FIND!!);
}
}
誰能向我解釋我做錯了什么?謝謝 :)
uj5u.com熱心網友回復:
我做了這個代碼:
List<bool> OutpuBool2 = [
false,
false,
false,
false,
false,
false,
false,
true,
false,
false,
false,
false,
true,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false
];
for (var i = 0; i < OutpuBool2.length; i ) {
if (OutpuBool2[i] == false) {
if (OutpuBool2[i 1] == true) {
print('There is a false with a true in the next index in index: $i');
}
}
}
這就是結果:在 index:6 的下一個索引中有一個 false 和一個 true 在 index:11 的下一個索引中有一個 false
這是你的意思嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/461255.html
下一篇:在for回圈中有條件地更新值
