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 and Flutter for loop multiple iterators

I have a for loop in my Flutter project similar to this (simplified):

for(int i=0; i<aVariableDeclaredBefore; i++) Padding(....

Here I need another operation after i++ run as this one anotherVariable–. I can’t do it in {} braces because loop used for Widget manipulation. There is no curly braces there.

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

I need something like this ((i++)&&(anotherVariable--)) but how ? if it is possible

>Solution :

Use the comma operator:

void main() {
  for (var i = 0, j = 10; i < 10; i++, j++) {
    print('i=$i, j=$j');
  }
}

Output:

i=0, j=10
i=1, j=11
i=2, j=12
i=3, j=13
i=4, j=14
i=5, j=15
i=6, j=16
i=7, j=17
i=8, j=18
i=9, j=19
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