# help with loops... :(

• November 2nd, 2010, 10:58 AM
Macgrubber
help with loops... :(
im doing a for loop that goes like this.... for (i=1 , i<=30000 , i++)
ok but want to printout a result every 1000 of the time.... how to do that.. please..
• November 2nd, 2010, 12:35 PM
javapenguin
Re: help with loops... :(
Quote:

Originally Posted by Macgrubber
im doing a for loop that goes like this.... for (i=1 , i<=30000 , i++)
ok but want to printout a result every 1000 of the time.... how to do that.. please..

Simple,

the % operator will return the remainder that's gotten from the division of two numbers.

If i%1000 = 0, that means it's divisible by 1000, i.e. i = 0, i = 1000, i = 2000, etc.

for (i = 1; i < = 30000; i++)
{
if (i%1000 ==0)
print out result
}
• November 2nd, 2010, 12:38 PM
copeg
Re: help with loops... :(
See Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics), mainly the remainder operator. Figure out when the remainder of i by 1000 is zero:
Code :

``` if ( i % 1000 == 0 ){   }```