title: Loop through 3d matrix with increment in each directions successively?
body: <p>I don't want this : </p>
  
  <pre><code>    for (int k=0; k&lt;X; k++) {
          for (int j=0; j&lt;X; j++) {
              for (int i=0; i&lt;X; i++) {
                  // do something
              }
          }
      }
  </code></pre>
  
  <p>Edit : this code snipet above will send the program to the following points : 
  (000) (001) (002) (003) (004) 
  then (for X = 5 ) 
  (010) (011) (012) (013) (014) 
  then 
  (020) (021) ...</p>
  
  <p>This is a waste of time for my program because I believe I will get results sooner by testing in this order :
  (0,0,0) (1,0,0) (1,1,0) (0,1,0) (0,1,1) (0,0,1) (1,0,1) etc... 
  A way to see it is to increment through the matrix with trying to get the smallest distance to (0,0,0) increment possible at each step.</p>
  
  <p>I hope it is more clear. </p>
  
  <p>Do you know a clever way to code that ? </p>
  
  <p>Edit : It totally matters for this problem solving to test the matrix points in this order.  </p>