Logo

Programming-Idioms

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

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another C++ implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
x = condition() ? "a" : "b";
if condition() {
	x = "a"
} else {
	x = "b"
}
x = "a" if condition() else "b"
if condition then
  x := a
else
  x := b;
uses math;
x := ifthen(condition, a, b);
x = if condition() { "a" } else { "b" };
x = condition() ? "a" : "b";
x = condition() ? "a" : "b";
x = condition ? "a" : "b"
const x = condition() ? 'a' : 'b';
x = if condition then 'a' else 'b'
let x | condition = "a"
      | otherwise = "b"
if (condition())
  x = a
else
  x = b
end if
if condition() then
   x := "a";
else
   x := "b";
end if;
x = if condition
      "a"
    else
      "b"
    end
my $x = condition() ? "a" : "b";
$x = condition() ? "a" : "b";
X = case Condition() of
	true -> "a";
	false -> "b"
end
val x = if(condition()) "a" else "b"
var x = condition() ? "a" : "b";
x := (if condition() then "a" else "b");
x := (if condition() then "a" else "b");
(def x (if condition
         "a"
         "b"))
x = if (condition()) "a" else "b"
x = if condition() then "a" else "b"
x = if condition(), do: "a", else: "b"
x = condition()? "a": "b";