Task

Loop over multiple arrays   (or lists or tuples or whatever they're called in
your language)   and display the    i th    element of each.

Use your language's   "for each"   loop if it has one, otherwise iterate
through the collection in order with some other loop.



For this example, loop over the arrays:

    (a,b,c)
    (A,B,C) 
    (1,2,3) 

to produce the output:

    aA1
    bB2
    cC3



If possible, also describe what happens when the arrays are of different lengths.



Related tasks

   Loop over multiple arrays simultaneously
   Loops/Break
   Loops/Continue
   Loops/Do-while
   Loops/Downward for
   Loops/For
   Loops/For with a specified step
   Loops/Foreach
   Loops/Increment loop index within loop body
   Loops/Infinite
   Loops/N plus one half
   Loops/Nested
   Loops/While
   Loops/with multiple ranges
   Loops/Wrong ranges


	org	100h
	lxi	b,0	; Let (B)C be the array index
outer:	lxi	d,As	; Use DE to walk the array-of-arrays
inner:	xchg		; Swap DE and HL (array-of-array pointer into HL)
	mov	e,m	; Load low byte of array pointer into E
	inx	h
	mov	d,m	; Load high byte of array pointer into D 
	inx	h
	xchg		; Array base in HL, array-of-array pointer in DE
	mov	a,h	; Is HL 0?
	ora	l
	jz	azero	; If so, we are done.
	dad	b	; Otherwise, add index to array base
	mov	a,m	; Get current item (BC'th item of HL)
	call	chout	; Output
	jmp	inner	; Next array 
azero:	mvi	a,13	; Print newline	
	call	chout
	mvi	a,10
	call	chout
	inr	c	; Increment index (we're only using the low byte)
	mvi	a,Alen	; Is it equal to the length?
	cmp	c
	jnz	outer	; If not, get next item from all the arrays.
	ret		
	;;;	Print character in A, saving all registers.
	;;;	This code uses CP/M to do it.
chout:	push 	psw	; CP/M destroys all registers
	push	b	; Push them all to the stack
	push	d
	push	h
	mvi	c,2	; 2 = print character syscall
	mov	e,a
	call	5
	pop	h	; Restore registers
	pop	d
	pop	b
	pop	psw
	ret
	;;;	Arrays
A1:	db	'a','b','c'
A2:	db	'A','B','C'
A3:	db	'1','2','3'
Alen:	equ	$-A3
	;;;	Zero-terminated array-of-arrays
As:	dw	A1,A2,A3,0