Concise way to write a if then else type statement

c, c++

Solution

The shortest thing I can think of is:

iQuantity += (bBoolean) ? -iDelta : iDelta;

Edit: This is commonly called a ternary statement, though it's proper name (what it's called in the standard) is "conditional expression" or "conditional operator".

(Thanks to Rune for the official name.)

Problem

Let's say I have a criteria and I want to add a delta if that criteria is true, and do the opposite (subtract) if it is false. ``` bool bBoolean; int iDelta; int iQuantity; ``` Is there a more concise and elegant way to write that piece of code ? I mean without repeating the keywords iQuantity and iDelta. ``` if(bBoolean) iQuantity -= iDelta; else iQuantity += iDelta; ```

Original source