Loops/For with a specified step: Difference between revisions

Content added Content deleted
(Gave more comprehensive examples including decrementing)
Line 2,043: Line 2,043:


=={{header|Nim}}==
=={{header|Nim}}==
<syntaxhighlight lang="nim">for x in countup(1, 10, 4): echo x</syntaxhighlight>
<syntaxhighlight lang="nim">

for n in 5 .. 9: # 5 to 9 (9-inclusive)
echo n

echo "" # spacer

for n in 5 ..< 9: # 5 to 9 (9-exclusive)
echo n

echo "" # spacer

for n in countup(0, 16, 4): # 0 to 16 step 4
echo n

echo "" # spacer

for n in countdown(16, 0, 4): # 16 to 0 step -4
echo n

</syntaxhighlight>
{{out}}
{{out}}
<pre>10
<pre>
1
5
5
6
9</pre>
7
8
9

5
6
7
8

0
4
8
12
16

16
12
8
4
0
</pre>


=={{header|N/t/roff}}==
=={{header|N/t/roff}}==