Dart For...in loop

Jinali GhoghariJinali Ghoghari
1 min read

Let's start with the basics.

Its syntax is relatively simple:

for (var item in collection) {
  // Body of the loop
}

Here's a breakdown of the syntax:

  • for: This keyword signals the start of the loop.

  • var item: This declares a loop variable (item) that represents each element or key in the collection during each iteration. You can replace var with the specific type if you know the type of the elements in the collection.

  • in: This keyword is used to specify the collection over which the loop iterates.

  • collection: This is the collection over which the loop iterates. It can be a list, set, map, or any iterable object.


Here is an example of using a for...in loop with a list.

0
Subscribe to my newsletter

Read articles from Jinali Ghoghari directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jinali Ghoghari
Jinali Ghoghari