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

m
m (→‎With indexed loop word: reverted behaviour of end.)
(2 intermediate revisions by 2 users not shown)
Line 1,907:
=={{header|EasyLang}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang=easylang>
fastfunc isprim num .
if num mod 2i = 0 and num > 2
return 0
.
i = 3
while i <= sqrt num
if num mod i = 0
return 0
.
i += 21
.
return 1
Line 1,944 ⟶ 1,941:
n=42 99504028301131
</pre>
 
=={{header|EMal}}==
{{trans|Java}}
<syntaxhighlight lang="emal">
int LIMIT = 42
fun isPrime = logic by int n
if n % 2 == 0 do return n == 2 end
if n % 3 == 0 do return n == 3 end
int id = 35
while d * d <= n
if n % d == 0 do return false end
d += 2
if n % d == 0 do return false end
d += 4
end
return 0true
end
for int i = LIMIT, int n = 0; n < LIMIT; ++i
if not isPrime(i) do continue end
++n
writeLine("n = " + n + ",\ti = " + i)
i += i - 1
end
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 5,197 ⟶ 5,218:
{{libheader|Wren-fmt}}
Although it might appear as though one can change the index variable within a ''for'' loop, it does in fact change a local copy of the variable and the iteration is not affected at all. Consequently, the only way to complete this task in Wren is to use a ''while'' loop.
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var isPrime = Fn.new { |n|
2,060

edits