Jump to content

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

m
→‎{{header|Phix}}: is_prime() now a builtin
(Added R solution)
m (→‎{{header|Phix}}: is_prime() now a builtin)
Line 3,101:
 
=={{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.
<lang Phix>atom i=42, n=1
while n<=42 do
if prime_factorsis_prime(i)={} then
printf(1,"n = %-2d %,19d\n", {n, i})
n += 1
7,820

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.