Iterators: Difference between revisions

Content added Content deleted
mNo edit summary
No edit summary
Line 316: Line 316:
Where iterators really shine; when you are collating the values from several infinite generators.
Where iterators really shine; when you are collating the values from several infinite generators.
(1 2 3 4 5 8 9 16 25 27 32 64 81 125 128 243 256 512 625 729 1024 2048 2187 3125 4096)</pre>
(1 2 3 4 5 8 9 16 25 27 32 64 81 125 128 243 256 512 625 729 1024 2048 2187 3125 4096)</pre>

=={{header|Ring}}==
<lang ring>
list = [["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
["Red","Orange","Yellow","Green","Blue","Purple"]]
ind = [1,4,5]
revInd = reverse(ind)

see "working..." +nl
see "All elements:" + nl

for n = 1 to len(list)
for m = 1 to len(list[n])
see list[n][m] + " "
next
see nl
next

see nl + "First, fourth, and fifth elements:" + nl

for n = 1 to len(list)
for m = 1 to len(ind)
see list[n][m] + " "
next
see nl
next

see nl +"Reverse first, fourth, and fifth elements:" + nl

for n = 1 to len(list)
for m = 1 to len(revInd)
see list[n][m] + " "
next
see nl
next

see "done..." +nl
</lang>
{{out}}
<pre>
All elements:
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
Red Orange Yellow Green Blue Purple

First, fourth, and fifth elements:
Sunday Monday Tuesday
Red Orange Yellow

Reverse first, fourth, and fifth elements:
Sunday Monday Tuesday
Red Orange Yellow
</pre>


=={{header|Wren}}==
=={{header|Wren}}==