Your tests (
i%j==0 and
i==j) are true for every
i, since your inner loop runs till
j is equal to
i.
It's not a good
test either. Prime number is a number which is divisible only by one and itself.
You should be looking for numbers (
n) that do not have any divisor between
2 and
n-1. Try to rewrite your condition that way.
(However, this is still quite inefficient way to find primes. There are many possible optimizations. For example, no prime except 2 is even, so you might put in 2 in advance and then only test odd numbers starting at three. And there are others. If you're really interested, I'd suggest doing a small research on prime numbers first.)