user
Task

Demonstrate a   *for-loop*   where the step-value is greater than one.

Related tasks

* Loop over multiple arrays simultaneously
* Loops/Break
* Loops/Continue
* Loops/Do-while
* Loops/Downward for
* Loops/For
* Loops/For with a specified step
* Loops/Foreach
* Loops/Increment loop index within loop body
* Loops/Infinite
* Loops/N plus one half
* Loops/Nested
* Loops/While
* Loops/with multiple ranges
* Loops/Wrong ranges
assistant
(formerly Perl 6)

**Works with**: Rakudo version 2010.07

Depending on how you define your terms, this task is either trivial or impossible in Raku. `for` in Raku doesn't have a step value, it's an iteration operator. It iterates through any iterable object passed to it and sets the topic variable to each iterated value in turn. If you close one eye and squint, I guess you could say it has a step value of 1 (or more accurately, Next) and that isn't really changeable. Whatever iterable you pass to it though can have pretty much any value in pretty much any order you desire, so effectively the "step" value is completely unconstrained.

Examples of iterables (not exhaustive):

* Things that do a positional role:

:   * Array
    * List
    * Range
    * Sequence

* Things that do an associative role:

:   * Bag
    * BagHash
    * Hash
    * Map
    * Mix
    * MixHash
    * QuantHash
    * Set
    * SetHash

Probably the most straightforward way to do this is with a sequence. With at least two values on the left-hand side, the sequence operator (`...`) can infer an arithmetic series. (With at least three values, it can infer a geometric sequence, too.)

```
for 2, 4 ... 8 {
    print "$_, ";
}
 
say 'whom do we appreciate?';
```

But there is nothing constraining the sequence to a constant step. Here's one with a *random* step.

```
.say for rand, *+rand-.5 ... *.abs>2
```

Sample output:

```
0.1594860240843563
-0.11336537297314198
-0.04195945218519992
-0.024844489074366427
-0.20616093727620433
-0.17589258387167517
-0.40547336592612593
0.04561929494516015
0.4886003890463373
0.7843094215547495
0.6413619589945883
1.0694380727281951
1.472290164849169
1.8310404939418325
2.326272380988639

```

For that matter, the iterated object doesn't need to contain numbers.

```
.say for <17/32 π banana 👀 :d(7) 🦋>;
```