Loops/Increment loop index within loop body: Difference between revisions

→‎{{header|Quackery}}: added second solution
imported>Joeypas
(→‎{{header|Quackery}}: added second solution)
Line 4,151:
 
=={{header|Quackery}}==
 
===With indexed loop word===
 
Quackery has an iterative looping word that can change its step size mid-iteration (see [[Loops/For with a specified step#Quackery]]) but it is not well suited to this task. A better solution (i.e. more idiomatic) is to define a new looping word that exactly meets the specification of the task.
Line 4,258 ⟶ 4,260:
41: 49,752,014,150,467
42: 99,504,028,301,131</pre>
 
===Without indexed loop word===
 
<code>prime</code>is defined at [[Miller–Rabin primality test#Quackery]].
 
<code>echo,</code> is as above.
 
<syntaxhighlight lang="Quackery"> 0 42
[ dup prime if
[ dip 1+
over echo
say ": "
dup echo, cr
dup + ]
1+
over 42 = until ]
2drop
</syntaxhighlight>
 
{{out}}
 
Output is as above.
 
=={{header|R}}==
1,462

edits