Loops/For with a specified step: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: indented DO loop, change to use '''output''' template. -- ~~~~)
(Add XPL0 example)
Line 841: Line 841:
i.print()
i.print()
}</lang>
}</lang>

=={{header|XPL0}}==
The 'for' loop always steps by 1 (or -1 for 'downto'). However there is
no restriction on how the control variable can be used or manipulated,
thus a step by 2 can be implemented like this:

<lang XPL0>include c:\cxpl\codes;
int I;
[for I:= 2 to 8 do
[IntOut(0, I); Text(0, ", ");
I:= I+1;
];
Text(0, "who do we appreciate?");
]</lang>

Output:
<pre>
2, 4, 6, 8, who do we appreciate?
</pre>


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==