Flutter ● ● ○

Kodebits Day 92: Collection For Loop

Sep 14 2026
Practice collections with a short dart challenge.

What is the output?

void main() {
  final nums = [1, 2, 3];
  final out = [
    for (var n in nums) n * 2
  ];
  print(out.length + out[0]);
}


Try it in the online Dart Playground →

[spoiler title="Solution"]

Answer:

5

Explanation:

A collection for builds a new list by transforming each source item.

[/spoiler]


Further Reading