Ok this code made me laugh -- I had better explain.
So let us consider each line in turn [note i have expanded the formatting]
for(int=2;i<1000;i++) // Simple loop
{
for(j=2;i/j;j++) // Loop to do j=2 to j < i : it works because
// integer arithmetic is being used
The i/j uses the fact that integer division ignores the division remainder,
e.g. 5/2 == 1 but 3/4 ==0 . Just writing i/j also uses the fact that any integer other than 0 is true.
To see the effect of i/j consider this
i j i/j
8 1 8
8 2 4
8 3 2
8 4 2
8 5 1
8 6 1
8 7 1
8 8 1
8 9 0
Continuing
// continued from above:
if (!(i%j)) break; // if j is a factor of i , exit the inner (j) loop.
if (j>(i/j)) // Test to see if all possibilities for have been
// used since you don't need to test beyond sqrt(i)
// Anything beyond that means it must be a prime
Note that (j>(i/j))
is a way of saying j*j>i
. I think that latter is clearer
Hope that helps...
I guess I was more surprised by the way the whole code was written in a divisional style.