# Understanding a logical expression

What is this expression saying? Specifically what part do the numbers at the end of each statement represent? Variables? True/False?

{If(Influence==0,0,If(Control==1,2,1))}

This is from Twilight Struggle. Influence = the number on the counter; Control = the counter image (controlled or uncontrolled).
Thx
Cavan

The syntax is `if(expression, result if expression is true, result if expression is false)`.
So, that above expression is saying if Influence is equal to 0, return 0; otherwise, if Control is equal to 1, return 2; otherwise, return 1.

Or, see Markâ€™s more complete explanation, just below (which appeared a split second after I posted; LOL).

1 Like

The syntax is: If(condition, outcome_if_true, outcome_if_false)

So in long form, the TS example means:
If the number on the counter is zero (or blank), make it zero.
Otherwise, flip `Control` between 1 and 2 (presumably these are Levels in an image Layer).

If you are writing If statements, consider the ternary operator instead. It is more concise and much better for chaining conditions. The TS example would look like this:
`{Influence == 0 ? 0 : Control == 1 ? 2 : 1}`

Thanks. Your examples make it much clearer.

To your parenthetical - yes the switching between â€ś1â€ť and â€ś2â€ť has to do with Levels in an Image Layer. Which makes your tertiary operand example make more sense to even someone who doesnâ€™t understand the language, since I at least can see a difference between a â€ś?â€ť and a â€ś:â€ť .

Just to be a bit pedantic but `?:` is the ternary conditional operator, not the tertiary operatorâ€“so called because it takes 3 operands, rather than the typical binary operator, which only takes 2. (There are also unary operators, such as `!` for negation.)

1 Like

Yes, it took me 10 minutes away from the computer but I eventually realised my error. Corrected.