for(j=2; j <= (i/j); j++) // efficient way to say j <= square root of i
if(!(i%j)) break; // if factor found, not prime
Starting at 2, and going up to the square root of i, check to see if i is divisible by j.
The reason for this is if no integer less than or equal to the number's square root can evenly divide the number, we know it's not going to match anything bigger.
Think about it. If we know 17 isn't divisible by 2, 3, or 4, we know it's prime, because to be divisible by two numbers greater than 4, it'd have to be at least 25.