# Thread: If (statement) and (statement)

1. ## If (statement) and (statement)

Hi, how to have muilti-conditions on an IF statment? 2. Code:
```if (a == b && c == d)
{
// true
}``` 3. thanks, this board ROCKS! Im almost done my first c++ program, TIC TAC TOE! 4. hm,, why this dont work
Code:
`if (playerturn % 2 == 1 && boardarray2[moverow][movecollumn]=false)` 5. For the sake of an example, let's deal with expressions with integer values:

In C, expressions that evaluate to non-zero values are considered "True" when participating in logical operations. Expressions that evaluate to zero are considered "False".

Here's the example using the && logical operator:

Code:
```if (first_stuff && second_stuff) {

// This is executed if both are true

}

else {

// This is excuted if neither is true

}```
Here's how it goes: first_stuff is evaluated. If it has a zero value, control passes to the else block. If first_stuff has a non-zero value, second_stuff gets evaluated. If this has a zero value, control passes to the else block. The only way that the first block in this example ever gets executed is whenever both first_stuff and second_stuff are non-zero (true).

Dave 6. Code:
`if (playerturn % 2 == 1 && boardarray2[moverow][movecollumn]=false)`
= should be ==. 7. >>boardarray2[moverow][movecollumn]=false)
How many equals sign are needed to test two variables? Two. One is an assignment, not a comparison.

Doh! beat. 8. But isn't it: if( true )? That means instead of == false you could also do: if( !condition ). ! meaning not, and that being true, the same thing as false. Right?

- SirCrono6 9. >Right?
Right (since we are talking about a boolean value). If you were talking about a general test against 0 then I would probably disagree on the grounds that using (!condition) when (condition == 0) would be more sensible results in obscure code. But if the condition being tested really is boolean in nature, (!condition) is usually more clear. Popular pages Recent additions 