Loops/For with a specified step: Difference between revisions
Content added Content deleted
(Logo) |
(added php, python3) |
||
Line 31: | Line 31: | ||
for [i 2 8 2] [type :i type "|, |] print [who do we appreciate?] |
for [i 2 8 2] [type :i type "|, |] print [who do we appreciate?] |
||
</lang> |
</lang> |
||
=={{header|PHP}}== |
|||
<lang php><?php |
|||
foreach (range(2, 8, 2) as $i) |
|||
echo "$i, "; |
|||
echo "who do we appreciate?\n"; |
|||
?></lang> |
|||
Output |
|||
<pre>2, 4, 6, 8, who do we appreciate?</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{works with|Python|2.x}} |
|||
⚫ | |||
<lang python>for i in xrange(2, 9, 2): |
|||
print "%d," % i, |
print "%d," % i, |
||
print "who do we appreciate?"</lang> |
print "who do we appreciate?"</lang> |
||
{{works with|Python|3.x}} |
|||
⚫ | |||
print("%d, " % i, end="") |
|||
print("who do we appreciate?")</lang> |
|||
Output |
Output |
||
<pre>2, 4, 6, 8, who do we appreciate?</pre> |
<pre>2, 4, 6, 8, who do we appreciate?</pre> |