for / each
Ranges and iterating over collections.
Syntax
for (x in collection) { ... } // (1..n).each { ... }Description
The range 1..3 includes 3. for-in iterates over the elements of a list or range in order. .each { } can also be used.
Example
Loading editor…
Expected output
1 2 3
When to use?
List processing, repetitive tasks.