title: looping through a 2D array 3 items at a time (Java)
body: <p>I am having trouble trying to figure out a way to move through a 2D array 3 items at a time mostly because it has to be done in a specific way. </p>
  
  <p>The array itself has individuals as rows and loci for columns. I have to take 2 individuals at a time and compare them with every third until the end: </p>
  
  <pre><code>So if there are 5 individuals the total individual comparisons would be
  0,1,2, 0,1,3, 0,1,4, 1,2,3, 1,2,4 and 2,3,4
  </code></pre>
  
  <p>For each of these comparisons, I have to compare their alleles at each locus (each column represents an allele, so two columns is one locus). So it looks something like this </p>
  
  <pre><code>   locus1 locus2 locus3 ...  
     0  1   2  3   4  5 
   0 1  2   3  4   5  6 
   1 7  8   9  10  11 12
   2 13 14  15 16  17 18 
   3 19 20  21 22  23 24
   4 25 26  27 28  29 30 
  
  As a definite example of what I mean, say I have the first set: 0,1,2. 
  The first comparison would be of the alleles: 1,2, 7,8 and 13, 14. 
  The next comparison would be of the alleles: 3,4, 9,10 and 15,16.
  The last (assuming three loci) would be: 5,6, 11,12, and 17,18.
  </code></pre>
  
  <p>For every set of 6 alleles, I have to do a comparison. I already have finished the code for the comparison testing. Im just not sure how to properly loop through this 2D array. What I am thinking about is psuedo-code like this: </p>
  
  <pre><code> for each pair of individuals (i,j)
     for each locus l 
       for each individual k, not i or j
         if comparison test works 
           great
         else 
           better luck next time
  </code></pre>
  
  <p>I do not want a direct answer. I would just like guidance as to how to tackle this keeping array boundaries in mind. I have not done a search like this before. </p>
  
  <p>I appreciate any help! Thanks :)</p>