<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: BadRockk</title>
    <description>The latest articles on DEV Community by BadRockk (@badrockk).</description>
    <link>https://dev.to/badrockk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F891261%2F7598727f-8410-4d0a-9b2c-807c8ac526e3.png</url>
      <title>DEV Community: BadRockk</title>
      <link>https://dev.to/badrockk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/badrockk"/>
    <language>en</language>
    <item>
      <title>dynamic loop for parameter combinations</title>
      <dc:creator>BadRockk</dc:creator>
      <pubDate>Wed, 13 Jul 2022 09:19:19 +0000</pubDate>
      <link>https://dev.to/badrockk/dynamic-loop-for-parameter-combinations-2oi0</link>
      <guid>https://dev.to/badrockk/dynamic-loop-for-parameter-combinations-2oi0</guid>
      <description>&lt;p&gt;Hi there,&lt;/p&gt;

&lt;p&gt;I'm doing JavaScript programming for a short time and I could solve most of my problems on my own searching the web. Most of my programming has been done in Excel VBA so my thinking maybe is still influenced by that.&lt;/p&gt;

&lt;p&gt;I use JavaScript in a calculation tool to performe multiple calculations automatically.  &lt;/p&gt;

&lt;p&gt;My problem is that I need to setup a dynamic loop to start the calculation with all possible combinations of parameter values.&lt;/p&gt;

&lt;p&gt;I have multiple objects like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parameter_01 = {
  trigger: "trigger_01"
  values : [0,2,5]
  }
parameter_02 = {
  trigger: "trigger_02"
  values : [3,6]
  }
...
parameter_xx = {
  trigger: "trigger_xx"
  values : [8,5,9,7,5]
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The number of parameters and values can change so I don't want to implement a fixed serial of loops iterating each parameter. My first thought is to declare an additional object that contains all parameters I want to take into the calculation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;all_parameters = [parameter_01, parameter_02, ... , parameter_xx]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I would need someting like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (var each_paramter of all_parameters) {
    for (var i of each_parameter[values]) {
        setAttr(each_parameter[trigger],i); // This is to set the parameter value in my calculation program
        for (var each_paramter+1 of all_parameters) {
             for (var j of each_parameter+1[values]) {
             setAttr(each_parameter+1[trigger],j);
             ...
                 for (var each_paramter+x of all_parameters) {
                      for (var x of each_parameter+x[values]) {
                      setAttr(each_parameter+1[trigger],x);
                      run_calulation;
                      }
                 }
             }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is it possible to create such a dynamic loop? Maybe I'm just searching with the wrong key words. I would appreciate every tip or link that could help me to solve this problem. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>help</category>
    </item>
  </channel>
</rss>
