title: Having issues with project euler 23 (loops)
body: <p>for some reason, I am having trouble with the loop in the first method of my code, ans. if you look at the do while and while loops, the while loop is working fine, running through each element in the LinkedHashSet, though the do-while stops after the while has had its first run through. So num1 doesn't move passed 12, while num2 successfully becomes every value in the Set, and I am not sure why. I figured this out by printing num1 and num2, and I am unable to figure out why this is happening. Any and all help is appreciated. Here is my code:</p>
  
  <pre><code>import java.util.Set;
  import java.util.LinkedHashSet;
  import java.util.Iterator;
  public class main{
  public static int ans(Set&lt;Integer&gt; abund,int total){
      int sum;
      Object num1;
      Object num2;
      Iterator itr=abund.iterator();//creates iterator to get values from set
      do{//loop to get all values from set
          num1=itr.next();//assigns each object in set to a num
          while (itr.hasNext()){//loop to get all values from set to add
              num2=itr.next();//assigns each object in set to a num
              sum=((int) num1+(int) num2);
              total-=sum;
          }
      }while (itr.hasNext());
      return total;
  }
  
  public static boolean abun(int y){
      int x;
      int facsum=0;
      for(x=1;x&lt;y;x++){
          if (y%x==0){
              facsum+=x;
          }
      }
      if (facsum&gt;y){
          return true;
      }
      else{
          return false;
      }
  }
  
  public static void main(String[] args){
      int x;//for loop counter
      int y;//another for loop counter
      int total=0;//total of all numbers from 0-28123
      int fin;//final answer
      boolean abundant;
      Set&lt;Integer&gt; abund=new LinkedHashSet&lt;Integer&gt;();
      for (x=0;x&lt;28124;x++){
          abundant=abun(x);
          if (abundant==true){
              abund.add(x);
          }
          total+=x;
      }
      fin=ans(abund,total);
      System.out.println("Final: "+fin);
  
  }
  }
  </code></pre>
  
  <p>Thanks</p>