For others reading this, I was wrong, it
was meant to be formatted that way...
This post is bad don't read it.
First, it looks like you want braces around your inner for loop.
Second, realize that i/j
truncates the answer to an integer (edit: Although that's not really the problem here), plua this doesn't make much sense to begin with, seeing as you're trying to check for primes.
Look at what will happen on the first run through:
* i will be 2
* j will be 2
* for loops then checks if 2 <= (2/2)
* this is false, so it won't even execute from the start.
If you initialized your for loop as for (int i = 2; i < 100; i++)
and likewise for the j-loop, it would prevent you from accidentally using "i", or "j" when you didn't mean to. (If you're working in C though, your compiler might not like this.)
This part is still good
___________________
// "if(!(i%j)) break; " It is this line i don't understand. |
This works because 0 evaluates to false, and 1 evaluates to true, and !0 == 1.
Ex:
i = 4,
j = 2,
it will check 4 mod 2, which is 0. Then it negates the 0, making it a 1, and this 1 is seen as "true" to the if statement.
Others may disagree but I find this notation really annoying to work with,
it would be much easier to read as
if (i%j == 0)
(In English, if i is divisible by j)