title: how can I program a large number of for loops
body: <p>I'm new to programming so I'm sorry in phrasing if I'm not asking this question correctly.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>int sum = 100;
  int a1 = 20;
  int a2 = 5;
  int a3 = 10;
  for (int i = 0; i * a1 &lt;= sum; i++) {
      for (int j = 0; i * a1 + j * a2 &lt;= sum; j++) {
          for (int k = 0; i * a1 + j * a2 + k * a3 &lt;= sum; k++) {
              if (i * a1 + j * a2 + k * a3 == sum) {
                  System.out.println(i + "," + j + "," + k);
              }
          }
      }   
  }
  </code></pre>
  
  <p>basically what it does is tell me the different combinations of <code>a1</code>, <code>a2</code>, and <code>a3</code> that equal the above sum (in this case 100).  This works fine but I'm trying to apply it to a larger dataset now and I'm not sure how to do without manually programming the for loops or knowing in advanced how many variables I'll have(could be anywhere from 10 to 6000).  I basically have a sql query that loads that data from an array.</p>
  
  <p>Is there a way in Java OR python (I'm learning both) to automatically create nested <code>for</code> and <code>if</code> loops?</p>
  
  <p>Thanks so much in advance.</p>