<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Iterate through all combinations of values from ARBITRARY number of lists in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Iterate-through-all-combinations-of-values-from-ARBITRARY-number/m-p/386030#M63616</link>
    <description>&lt;P&gt;Can somebody suggest a solution to this.&lt;/P&gt;&lt;P&gt;I have multiple lists. I need to iterate through all possible combinations of values from these lists. The problem is that the number of lists I'm taking values from is decided at runtime. So I cannot write two nested 'for' loops for two lists and then three nested 'for' loops for three lists. I need somehow to pass\parse names of the lists (probably as a list itself) and then iterate through all of the lists\values in the lists.&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 19:47:05 GMT</pubDate>
    <dc:creator>miguello</dc:creator>
    <dc:date>2023-06-09T19:47:05Z</dc:date>
    <item>
      <title>Iterate through all combinations of values from ARBITRARY number of lists</title>
      <link>https://community.jmp.com/t5/Discussions/Iterate-through-all-combinations-of-values-from-ARBITRARY-number/m-p/386030#M63616</link>
      <description>&lt;P&gt;Can somebody suggest a solution to this.&lt;/P&gt;&lt;P&gt;I have multiple lists. I need to iterate through all possible combinations of values from these lists. The problem is that the number of lists I'm taking values from is decided at runtime. So I cannot write two nested 'for' loops for two lists and then three nested 'for' loops for three lists. I need somehow to pass\parse names of the lists (probably as a list itself) and then iterate through all of the lists\values in the lists.&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:47:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterate-through-all-combinations-of-values-from-ARBITRARY-number/m-p/386030#M63616</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2023-06-09T19:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through all combinations of values from ARBITRARY number of lists</title>
      <link>https://community.jmp.com/t5/Discussions/Iterate-through-all-combinations-of-values-from-ARBITRARY-number/m-p/386062#M63618</link>
      <description>&lt;P&gt;I'm not sure how deep this can go before JMP thinks your recursion is too deep, so test first...If you have too many lists, there is a slightly less pretty work-around using a stack. But if each list has at least two elements, I think you'll run out of time first.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// the variable length list of variable length lists
L = {{"a", "b"}, {"c"}, {"d", "e", "f"}, {"g", "h", "i", "j"}};

result = {}; // a place to accumulate the results
p = {}; // a single result

// a recursive function to "nest the for loops"
generate = Function( {i}, // the "layer"
	{j}, // the local for-loop counter
	If( i &amp;gt; N Items( L ),
		result[N Items( result ) + 1] = p; // you could just use p at this point
		Return();
	);
	For( j = 1, j &amp;lt;= N Items( L[i] ), j += 1, // go through all the items at this layer
		Insert Into( p, L[i][j] ); // add each to the single result
		Recurse( i + 1 ); // go to next layer
		Remove From( p ); // remove from the single result
	);
);

generate( 1 ); // run the recursive function
Show( result );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;result = {&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "d", "g"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "d", "h"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "d", "i"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "d", "j"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "e", "g"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "e", "h"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "e", "i"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "e", "j"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "f", "g"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "f", "h"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "f", "i"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"a", "c", "f", "j"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "d", "g"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "d", "h"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "d", "i"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "d", "j"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "e", "g"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "e", "h"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "e", "i"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "e", "j"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "f", "g"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "f", "h"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "f", "i"}, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;{"b", "c", "f", "j"}&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;STRONG&gt;};&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 00:06:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterate-through-all-combinations-of-values-from-ARBITRARY-number/m-p/386062#M63618</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-05-18T00:06:18Z</dc:date>
    </item>
  </channel>
</rss>

