Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #252 Conditional assignment

Assign to variable x the value "a" if calling the function condition returns true, or the value "b" otherwise.

x = condition() ? "a" : "b";
x = condition() ? "a" : "b";
x = condition() ? "a" : "b";
if (condition())
  x = a
else
  x = b
end if
if condition() {
	x = "a"
} else {
	x = "b"
}
x = if condition then 'a' else 'b'
let x | condition = "a"
      | otherwise = "b"
const x = condition() ? 'a' : 'b';
x = condition() ? "a" : "b";
uses math;
x := ifthen(condition, a, b);
if condition then
  x := a
else
  x := b;
x = "a" if condition() else "b"
x = condition ? "a" : "b"
x = if condition() { "a" } else { "b" };

New implementation...
programming-idioms.org