Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does if(!(x%3)) mean?

Tags:

c++

I am attempting to solve a hw problem in which I need to write down what the program will output. I am stuck however, on the syntax "if ( !(i%3)). What does that really mean? Does it mean that the program is checking for any i that is divisible by three? aka, is the if statement only runs if i is divisible by three?

int main () {
for (int i=0; i<10; (i<3?i++;i+=2)) {
    if (!(i%3)) {
        continue;
    }
    else if (i%7 ==0) {
        break;
    }
    cout << i<< endl;
}
like image 969
nains Avatar asked Dec 07 '25 08:12

nains


1 Answers

Does it mean that the program is checking for any i that is divisible by three? aka, is the if statement only runs if i is divisible by three?

Correct. The longer version of that check would be

if (i % 3 == 0)
    continue;

The most common use case for such branching is probably FizzBuzz.

like image 195
lubgr Avatar answered Dec 08 '25 21:12

lubgr