user
Sometimes, one may need   (or want)   a loop which
its   *iterator*   (the index
variable)   is modified within the
  
loop body    *in addition to the normal incrementation by the   (**do**)   loop structure index*.

Goal

Demonstrate the best way to accomplish this.

Task

Write a loop which:

:   :   * starts the index (variable) at   **42**
        * (at iteration time)   increments the index by unity
        * if the index is prime:

        :   :   * displays the count of primes found (so far) and the prime   (to the terminal)
                * increments the index such that the new index is now the (old) index plus that prime

        * terminates the loop when   **42**   primes are shown

Extra credit:   because of the primes get rather large, use commas
within the displayed primes to ease comprehension.

Show all output here.

Note

Not all programming languages allow the modification of a
loop's index.   If that is the case, then use whatever method that
is appropriate or idiomatic for that language.   Please add a note
if the loop's index isn't modifiable.

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/Infinite
* Loops/N plus one half
* Loops/Nested
* Loops/While
* Loops/with multiple ranges
* Loops/Wrong ranges
assistant
(formerly Perl 6)
Hmm.

> Demonstrate the best way to accomplish this.

The *best* way is probably to not use an explicit loop. Just calculate the sequence directly.

```
# the actual sequence logic
my @seq = grep *.is-prime, (42, { .is-prime ?? $_+<1 !! $_+1 } … *);

# display code
say (1+$_).fmt("%-4s"), @seq[$_].flip.comb(3).join(',').flip.fmt("%20s") for ^42;

```

Output:

```
1                     43
2                     89
3                    179
4                    359
5                    719
6                  1,439
7                  2,879
8                  5,779
9                 11,579
10                23,159
11                46,327
12                92,657
13               185,323
14               370,661
15               741,337
16             1,482,707
17             2,965,421
18             5,930,887
19            11,861,791
20            23,723,597
21            47,447,201
22            94,894,427
23           189,788,857
24           379,577,741
25           759,155,483
26         1,518,310,967
27         3,036,621,941
28         6,073,243,889
29        12,146,487,779
30        24,292,975,649
31        48,585,951,311
32        97,171,902,629
33       194,343,805,267
34       388,687,610,539
35       777,375,221,081
36     1,554,750,442,183
37     3,109,500,884,389
38     6,219,001,768,781
39    12,438,003,537,571
40    24,876,007,075,181
41    49,752,014,150,467
42    99,504,028,301,131
```