Loops/Foreach: Difference between revisions

(XSLT)
Line 89:
</pre>
=={{header|Python}}==
<python>for i in collectcollection:
print i</python>
 
Note: The Python ''for'' statement is always a "foreach" ... and the ''range()'' and ''xrange()'' built-in functions are used to generate lists of indexes over which it will iterate as necessary. The majority of Python objects support iteration. Lists and tuples iterate over each item, strings iterate over each character, dictionaries iterate over keys, files iterate over lines, and so on.
 
For example:
 
<python>
lines = words = characters = 0
f = open('somefile','r')
for eachline in f:
lines += 1
for eachword in eachline.split():
words += 1
for eachchar in eachword:
chracters += 1
 
print lines, words, characters
</python>
 
=={{header|Ruby}}==
<ruby>for i in collection do
Anonymous user