Loops/Foreach: Difference between revisions

Content added Content deleted
No edit summary
(Added Dyalect programming language)
Line 792: Line 792:
}
}
</lang>
</lang>

=={{header|Dyalect}}==
<lang Dyalect>for i in [1,2,3] {
print(i)
}</lang>

This code would work for any type that has a method "iter" (which returns an iterator). In fact a runtime environment silently call this method for you and creates an iterator out of an array. The code above is absolutely identical to:

<lang Dyalect>for i in [1,2,3].iter() {
print(i)
}</lang>

This would perfectly work with any custom iterator as well:

<lang Dyalect>
func myCollection() {
yield 1
yield 2
yield 3
}

for i in myCollection() {
print(i)
}</lang>

All three code samples would output:

<pre>1
2
3</pre>


=={{header|E}}==
=={{header|E}}==