Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Ada

Idiom #252 Conditional assignment

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

if condition() then
   x := "a";
else
   x := "b";
end if;
x := (if condition() then "a" else "b");
x := (if condition() then "a" else "b");
x = condition() ? "a" : "b";

New implementation...
< >
programming-idioms.org