Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dart – Detects when in a list there is a 'false' with a 'true' in the next index

I would like to create a script in Dart that detects when in the OutputBool2 list there is a ‘false’ with a ‘true’ in the next index

I created this script, but it doesn’t seem to work:

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!!);

      }
    }

Can anyone explain to me what I’m doing wrong?
Thanks 🙂

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I made this code:

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');
      }
    }
  }

and this is the result:
There is a false with a true in the next index in index: 6
There is a false with a true in the next index in index: 11

is that what you meant?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading