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

Content added Content deleted
(→‎{{header|Wren}}: Now uses 'fmt' module. Changed preamble slightly.)
(→‎{{header|M2000 Interpreter}}: now is ok for indexes above 39)
Line 2,601: Line 2,601:
Function IsPrime (x) {
Function IsPrime (x) {
if x<=5 OR frac(x) then {
if x<=5 OR frac(x) then {
if x == 2 OR x == 3 OR x == 5 then =true
if x = 2 OR x = 3 OR x = 5 then =true
Break
Break
}
}
if frac(x/2 ) else exit
if x mod 2 else exit
if frac(x/3) else exit
if x mod 3 else exit
x1=sqrt(x): d=5
x1=sqrt(x): d=5@
{if frac(x/d ) else exit
{if x mod d else exit
d += 2: if d>x1 then =true : exit
d += 2@: if d>x1 then =true : exit
if frac(x/d) else exit
if x mod d else exit
d += 4: if d<= x1 else =true: exit
d += 4@: if d<= x1 else =true: exit
loop
loop
}
}
Line 2,618: Line 2,618:
\\ so we have to use Block iterator, using Loop which set a flag current block to repeat itself once.
\\ so we have to use Block iterator, using Loop which set a flag current block to repeat itself once.
def long Limit=42, n
def long Limit=42, n
def currency i
def decimal i
i=Limit
i=Limit
{
{
if n<limit Else exit
if n<Limit Else exit
if isPrime(i) then n++ : Print format$("n={0::2}: {1:-20}", n, str$(i,"#,###")) : i+=i-1
if isPrime(i) then n++ : Print format$("n={0::2}: {1:-20}", n, str$(i,"#,###")) : i+=i-1
i++
i++