Iterators: Difference between revisions
Content added Content deleted
m (J: show more detail about trailing empty example) |
(Iterators en BASIC256) |
||
Line 16: | Line 16: | ||
If you language supports iterators, use them. Otherwise show how access to elements can be |
If you language supports iterators, use them. Otherwise show how access to elements can be |
||
separated from the containers that hold them. |
separated from the containers that hold them. |
||
=={{header|BASIC256}}== |
|||
{{trans|FreeBASIC}} |
|||
<lang freebasic>arraybase 1 |
|||
dim list$ = {{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}, {"Red","Orange","Yellow","Green","Blue","Purple"}} |
|||
dim ind = {1,4,5} |
|||
print "All elements:" |
|||
for n = 1 to list$[?,] |
|||
for m = 1 to list$[,?] |
|||
print list$[n, m]; " "; |
|||
next m |
|||
print |
|||
next n |
|||
print |
|||
print "First, fourth, and fifth elements:" |
|||
for n = 1 to list$[?,] |
|||
for m = 1 to ind[?] |
|||
print list$[n, ind[m]]; " "; |
|||
next m |
|||
print |
|||
next n |
|||
print |
|||
print "Reverse first, fourth, and fifth elements:" |
|||
for m = 1 to ind[?] |
|||
print list$[1, list$[,?]+1-ind[m]]; " "; |
|||
next m |
|||
print |
|||
for m = 1 to ind[?] |
|||
print list$[2, list$[,?]-ind[m]]; " "; |
|||
next m |
|||
print |
|||
end |
|||
</lang> |
|||
<pre>Igual que la entrada de FreeBASIC.</pre> |
|||
=={{header|C++}}== |
=={{header|C++}}== |