# Generating every combination oif values from Jagged Array RSS

## 4 replies

Last post Oct 31, 2012 09:22 AM by mayerwin

Member

223 Points

226 Posts

### Generating every combination oif values from Jagged Array

I have a scenario where I am trying to generate every combination of value from a jagged array - for example :

Array 1 :

Womens
Womans

Array 2 :

Overalls
Boiler Suit
Boilersuit
Coveralls

So I want to generate 12 strings in total e.g :

Womens Overalls
Womens Boilersuit
...
Womans Coveralls

So all in first array associated with all in second array.

I have created my jagged array with the values but I can't work out how to iterate through it and create all variations - I can iterate, but only get each value once at present.

Also on a related note this could do with working in the case of more than 2 arrays - i.e. a multiple number of arrays within the jagged array.

Thanks

• ### SGWellens

All-Star

126031 Points

10310 Posts

Moderator

### Re: Generating every combination oif values from Jagged Array

You want two loops, one nested inside the other.

The outer loop iterates the items in Array 1, the inner loop iterates over the items in Array 2.

Steve Wellens

My blog

Member

223 Points

226 Posts

### Re: Generating every combination oif values from Jagged Array

What if it's a flexible number of arrays - say 3 or 4 - I need a looping system that will draw out the values in each and create the resultant strings of all variations. One saving grace is that the combinations can be in order - i.e. the position in the resulting strings is dictated by which array is storing the value.

All-Star

45968 Points

2997 Posts

### Re: Generating every combination oif values from Jagged Array

#### chilluk

What if it's a flexible number of arrays - say 3 or 4 - I need a looping system that will draw out the values in each and create the resultant strings of all variations. One saving grace is that the combinations can be in order - i.e. the position in the resulting strings is dictated by which array is storing the value.

Hi,

It is hard to handle the case that if it's a flexible number of arrays. Please have a read at this article talking about Backtracking Algorithms: http://www.cse.ohio-state.edu/~gurari/course/cis680/cis680Ch19.html#QQ1-51-133. This will help.

Best Regards,
Shengqing Yang

Please mark the replies as answers if they help or unmark if not.
Microsoft One Code Framework

Member

2 Points

1 Post