On Wed, Dec 20, 2023 at 3:41 AM Artur T. <atecon(a)posteo.de> wrote:
Hi all,
Let's say we have a string array 'input'. The first example shows that
the for-loop can be used for printing each element of the array.
However, as the 2nd example shows, if the string array is stored in
bundle B this does not seem to work currently.
I could not find anything in the User's Guide about this restriction. Is
it expected that one cannot print the elements of B.input as can be done
for input itself?
<hansl>
input = defarray("R1", "R2", "R3")
bundle B = _(input)
# Prints each element
loop foreach i input
print "$i"
endloop
# prints only 'B.input'
loop foreach i B.input
print "$i"
endloop
</hansl>
Up till now, the assumption has been that an array or bundle featuring
in a "loop foreach" command must be a top-level object, not embedded
inside something else. In current git, however, that limitation is
relaxed. The following script illustrates what is now working.
<hansl>
strings input = defarray("R1", "R2", "R3")
# array of strings inside array
strings numbers = defarray("one", "two", "three")
arrays aa = defarray(input, numbers)
loop foreach i aa[2]
print "$i"
endloop
# array of strings inside bundle
bundle B = _(input)
loop foreach i B.input
print "$i"
endloop
# bundle inside array
bundles bb = array(2)
bb[1] = B
bb[2] = _(x=13, y=27, z="foo")
loop foreach i bb[2]
print "$i"
endloop
# array of strings inside bundle inside array
loop foreach i bb[1].input
print "$i"
endloop
</hansl>
Allin