# Idiom #252 Conditional assignment

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

``x = condition() ? "a" : "b";``
``````x := (if condition() then "a" else "b");
``````
``````x := (if condition() then "a" else "b");
``````
``````if condition() then
x := "a";
else
x := "b";
end if;``````
``x = condition() ? "a" : "b";``
``````(def x (if condition
"a"
"b"))``````
``x = condition() ? "a" : "b";``
``x = condition() ? "a" : "b";``
``var x = condition() ? "a" : "b";``
``x = if condition(), do: "a", else: "b"``
``````X = case Condition() of
true -> "a";
false -> "b"
end``````
``````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';``
``val x = if(condition()) "a" else "b"``
``\$x = condition() ? "a" : "b";``
``````if condition then
x := a
else
x := b;``````
``uses math;``
``x := ifthen(condition, a, b);``
``my \$x = condition() ? "a" : "b";``
``x = "a" if condition() else "b"``
``````x = if condition
"a"
else
"b"
end``````
``````x = condition ? "a" : "b"
``````
``x = if condition() { "a" } else { "b" };``
``x = if (condition()) "a" else "b"``
``x = if condition() then "a" else "b"``

programming-idioms.org