how to do nested loops of variable depth?

Baveco, Hans J.M.Baveco at Alterra.wag-ur.nl
Wed Dec 19 08:46:31 UTC 2001


when I have the simple case of 2 arrays and I want to combine each value of
the first with each value of the second, I know what to do.
Something like 
	result := OrderedCollection new: (array1 size * array2 size).
	1 to: array1 size do: [:i | 1 to: array2 size do: [:j | result
addLast: (Array with: (array1 at: i) with: (array2 at: j))].
will do the trick.
Of course this can be extended to any required depth of nesting (=number of
input arrays).
However, what would be the smalltalk way to handle a variable number of
input arrays (=variable depth of nesting)? I guess there must be some smart
(recursive) way to deal with this problem in smalltalk/squeak. 
Can anyone set me on the right track?

hans




More information about the Squeak-dev mailing list