# multiple if cond.

• 05-29-2006
vikernes
multiple if cond.
Hi,

Sorry about this noob question, but I'm obviously retarded or too tired to know why this isn't working:

Code:

```for(int i = 0; i < 20; i++)         {                 if(i%3 || i%5 || i%7)                         cout << i << endl;                         }```
The output is the same as if there's weren't no if statement.
• 05-29-2006
Ancient Dragon
yup -- it will print every loop value. Why? Pick any number between 0 and 20, then test it yourself.
• 05-29-2006
michaels-r
You are actually asking for all values of i which are not divisible by 3, 5 or 7 which means that the first number you would not show is 21 (beyond your range). Perhaps you ment to use && instead?
• 05-29-2006
King Mir
3*5*7 is greater than 20. That statement will only evaluate to false if 'i' is a multiple of 105.
• 05-29-2006
vikernes
Yes michaels that's what I wanted to do, but isn't || the OR operator? Meaning if i is divisible with 3 or 5 or 7, skip it?
• 05-29-2006
King Mir
Quote:

Originally Posted by vikernes
Yes michaels that's what I wanted to do, but isn't || the OR operator? Meaning if i is divisible with 3 or 5 or 7, skip it?

Yes, but modulous evaluates to false (0) if it is devisible. So the expression is esencially if i is not divisible by 3, 5, or 7.

So what you really want if either:
if(!(i%3)||!(i%5)||!(i%7))
or
if(!(i%3 && i%5 && i%7))