RosettaCodeData/Task/Loops-Increment-loop-index-within-loop-body/Icon/loops-increment-loop-index-within-loop-body.icon
2025-08-11 18:05:26 -07:00

40 lines
728 B
Text

procedure main()
I_START := 42
LIMIT := I_START
i := I_START
n := 0
until n = LIMIT do {
if is_prime(i) then {
n +:= 1
write(right(n,2),": ",comma_string(i))
i +:= i
} else
i +:= 1
}
end
procedure is_prime(n)
if n < 2 then fail
if n%2 = 0 then return n = 2
if n%3 = 0 then return n = 3
d := 5
while d*d <= n do {
if n%d = 0 then fail
d +:= 2
if n%d = 0 then fail
d +:= 4
}
return n
end
procedure comma_string(n)
s := ""
n ? {
tab(0)
while s := "," || move(-3) || s
if pos(1) then s := s[2:0]
else s := tab(1) || s
}
return s
end