RosettaCodeData/Task/Loops-Increment-loop-index-within-loop-body/S-BASIC/loops-increment-loop-index-within-loop-body.basic
2025-06-11 20:16:52 -04:00

41 lines
777 B
Text

$lines
$constant FALSE = 0
$constant TRUE = 0FFFFH
rem - return n mod m
function mod(n, m = integer) = integer
end = n - m * (n / m)
rem - return true if n is prime, otherwise false
function isprime(n = integer) = integer
var i, limit, result = integer
if n = 2 then
result = TRUE
else if (n < 2) or (mod(n,2) = 0) then
result = FALSE
else
begin
limit = int(sqr(n))
i = 3
while (i <= limit) and (mod(n, i) <> 0) do
i = i + 2
result = not (i <= limit)
end
end = result
var i, count = integer
count = 0
for i = 42 to 32760
if isprime(i) then
begin
count = count + 1
print using "## ##,###"; count; i
if count >= 10 then
i = 32760
else
i = i + (i - 1)
end
next i
end