Home > Blockchain >  Dart and Flutter for loop multiple iterators
Dart and Flutter for loop multiple iterators

Time:01-23

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.

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

CodePudding user response:

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
  • Related