Ternary expression which "does nothing" (noop) if the condition is false?

How about this:

variable = (someBool) ? i : variable ;

Though I would personally prefer the original if statement


The format of the conditional expression is

<expression> ? <expression> : <expression>

In other words, it must have some expression.


how about short-circuit?

int variable = 0;
bool cond = true; // or false

(cond && (variable = 42));

printf("%d\n", variable);

Compilers not only expect expression, but the expression the returns type on the left side (the type of variable whatever is it). So, no you can not do that. It's not conditional execution, but variable member assignment.

These are completely different things. In second example :

if (someBool) {
    variable = i;
}

you do not assign anything, but simply execute based on condition. So in your case, where you don't want to do anything (not assign anything), the way to go is conditional execution so use simply the second case.