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

Content added Content deleted
(Added R solution)
m (→‎{{header|Phix}}: is_prime() now a builtin)
Line 3,101: Line 3,101:


=={{header|Phix}}==
=={{header|Phix}}==
Phix does not allow for loop variables to be modified, so we must use a while loop and manual increment for this sort of thing. There is not, as yet, an is_prime() builtin. We can use prime_factors() returns {}, though it is probably a little bit slower as it builds the full list rather than yielding false asap - but at least we don't have to define an is_prime() function.
Phix does not allow for loop variables to be modified, so we must use a while loop and manual increment for this sort of thing.
<lang Phix>atom i=42, n=1
<lang Phix>atom i=42, n=1
while n<=42 do
while n<=42 do
if prime_factors(i)={} then
if is_prime(i) then
printf(1,"n = %-2d %,19d\n", {n, i})
printf(1,"n = %-2d %,19d\n", {n, i})
n += 1
n += 1