Iterators: Difference between revisions

Content added Content deleted
(A Python implementation)
No edit summary
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|68000 Assembly}}==
The easiest way to do this is with a table of pointers, as they're always 4 bytes regardless of the size of the data they point to.

Also, I'm making the assumption that the "Print the first, fourth, and fifth elements of each container" were intended to be one-indexed (i.e print the strings at offsets zero, three, and four)
<lang 68000devpac>main:

PrintAll:
MOVE.W #7-1,D7
MOVEQ #0,D1
.loop:
LEA Days_Of_The_Week,A0
MOVE.W D1,D2
LSL.W #2,D2
MOVEA.L (A0,D2),A3
JSR PrintString ;unimplemented hardware-dependent printing routine
ADDQ.W #1,D1
DBRA D7,.loop

Part2:
LEA Days_Of_The_Week,A0
MOVEA.L (A0),A3
JSR PrintString
MOVEA.L (12,A0),A3
JSR PrintString
MOVEA.L (16,A0),A3
JSR PrintString

Part3:
LEA Days_Of_The_Week,A0
MOVEA.L (24,A0),A3
JSR PrintString
MOVEA.L (12,A0),A3
JSR PrintString
MOVEA.L (8,A0),A3
JSR PrintString

JMP * ;HALT THE CPU

Days_Of_The_Week:
DC.L Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
; 0 4 8 12 16 20 24

Sunday:
DC.B "Sunday",0
EVEN ;conditionally aligns to a 2-byte boundary if the data isn't aligned already
Monday:
DC.B "Monday",0
EVEN
Tuesday:
DC.B "Tuesday",0
EVEN
Wednesday:
DC.B "Wednesday",0
EVEN
Thursday:
DC.B "Thursday",0
EVEN
Friday:
DC.B "Friday",0
EVEN
Saturday:
DC.B "Saturday",0
EVEN</lang>


=={{header|BASIC256}}==
=={{header|BASIC256}}==