Home > database >  Dart: iterate through lists in lists
Dart: iterate through lists in lists

Time:11-27

I have a list where it has values of another lists like this.

List[

    List[

        List[]
        ]
   ]          

       

I want to iterate through lists in lists until the last list is null.

How can I do this ?

CodePudding user response:

You can build a recursive function like this:

_loopRecursively(List<int> _list){
 for(int i=0;i<_list[i];i  ){
   if(_list[i] is List<int>){
     _loopRecuresively(_list[i]);
   }
 }
}

For recursive function references: https://www.geeksforgeeks.org/recursive-functions/

  • Related