Hi Prof!
i want to check for phase difference in multiple of integers, if the answer is
phi = 6.28
student can key in 0, 6.28, 6.28*2,6.28*3 etc until a large number

my initial codes are here


if (Math.abs(phi-2*0*Math.PI-enterphi) < 0.1||Math.abs(phi-2*1*Math.PI-enterphi) < 0.1||Math.abs(phi-2*2*Math.PI-enterphi) < 0.1||Math.abs(phi-2*3*Math.PI-enterphi) < 0.1)
{

phicorrect = "  Yes";
phicorrectbackground = java.awt.Color.GREEN;
}
else
{
phicorrect = "  No";
phicorrectbackground = java.awt.Color.RED;

}

[b]My question is how to do a loop?[/b]

i try
for (int counter=0; counter<100 /* Iterations */ ; counter++) {
 if (Math.abs(phi-2*counter*Math.PI-enterphi) < 0.1) {
   phicorrect = "  Yes";
   phicorrectbackground = java.awt.Color.GREEN;
 }
 else {
   phicorrect = "  No";
   phicorrectbackground = java.awt.Color.RED;

 }

but it did not check the phi is multiple of counter to accept answer as correct.
how to make the codes elegant?  ;D
thanks!

quite silly to write
  if (Math.abs(phi-2*0*Math.PI-enterphi) < 0.1||Math.abs(phi-2*1*Math.PI-enterphi) < 0.1||Math.abs(phi-2*2*Math.PI-enterphi) < 0.1||Math.abs(phi-2*3*Math.PI-enterphi) < 0.1||Math.abs(phi+2*1*Math.PI-enterphi) < 0.1||Math.abs(phi+2*2*Math.PI-enterphi) < 0.1||Math.abs(phi+2*3*Math.PI-enterphi) < 0.1) { // valid only for 3 rounds left and right
    phicorrect = "  Yes";
    phicorrectbackground = java.awt.Color.GREEN;
  }
  else {
    phicorrect = "  No";
    phicorrectbackground = java.awt.Color.RED;

  }