Civil Rights
Movements, leaders, victories and the continuing fight for equality.
Explore the people, places, events, achievements, struggles and stories that shaped our journey.
Movements, leaders, victories and the continuing fight for equality.
Innovation, patents, science, technology and world-changing contributions.
Pioneers, champions, Negro Leagues, records, activism and excellence.
Meet the people whose lives, choices and achievements shaped the journey.
Black towns, communities, institutions and places where history happened.
Moments that changed communities, movements, institutions and the nation.
Katherine Johnson’s mathematical calculations helped guide some of America’s most important early space missions while she confronted the racial and gender barriers faced by Black women in twentieth-century America.
MORE →Reflects the personal views, recollections, and perspective of the author, Mike Davis.
This is a personal recollection on the Move fire on May 13, 1985
In computer programming, the ternary conditional operator is a conditional expression with three parts: the Boolean condition, the then-expression, and the else-expression. If the condition is true, the then-expression is evaluated; otherwise, the else-expression is evaluated; and the value is returned. Thus it is a non-strict operator, like other conditional expressions. It is also called a conditional operator, ternary if, immediate if, or inline if (iif).
Although a ternary operator in general is any operator with three arguments, the three-argument conditional operator is the only common one in programming, so it is loosely called the ternary operator.
C introduced the syntax a ? b : c, read as "if a then b otherwise c", which is widely used by other languages with C-like syntax. Some languages use functional syntax: in Visual Basic, it is written If(a, b, c).
Many languages support conditional expressions with two, three, or more clauses. Languages following ALGOL-like syntax often support them with the same syntax as conditional statements, if a then b else c.
The construct first appeared in CPL in 1963, as a → b, c.[1][2]
The value of the operator can be assigned to a variable. For a weakly typed language, the data type of the selected value may determine the type of the assigned value. For a strongly typed language, both value expressions must evaluate to a type that is compatible with the target variable.
The operator is similar to the way conditional expressions (if-then-else) work in functional programming languages, like Scheme, ML, Haskell, and XQuery, since if-then-else forms an expression instead of a statement in those languages.
The operator allows for initializing a variable via a single statement which otherwise might require multiple statements. Use in variable assignment reduces the probability of a bug from a faulty assignment as the assigned variable is stated only once.
For example, in Python:
x: str = 'foo' if b else 'bar'
instead of:
x: str
if b:
x = 'foo'
else:
x = 'bar'
In a language with block scope, a variable must be declared before the if-else statement. For example:
std::string s;
if (b) {
s = "foo";
} else {
s = "bar";
}
Use of the conditional operator simplifies this:
std::string s = b ? "foo" : "bar";
Furthermore, since initialization is now part of the declaration, rather than a separate statement, the identifier can be a constant. For example:
const std::string s = b ? "foo" : "bar";
The conditional operator can be used for case selectors. For example:
vehicle = arg == 'B' ? bus :
arg == 'A' ? airplane :
arg == 'T' ? train :
arg == 'C' ? car :
arg == 'H' ? horse :
feet;
The syntax and semantics of the operator vary by language.
Major differences include whether the expressions can have side effects and whether the language provides short-circuit evaluation semantics, whereby only the selected expression is evaluated.
If a language supports expressions with side effects but does not specify short-circuit evaluation, then a further distinction exists about which expression evaluates first. If no order is guaranteed, a distinction exists about whether the result is then classified as indeterminate (the value obtained from some order) or undefined (any value at all at the whim of the compiler in the face of side effects, or even a crash).
If a language does not permit side-effects in expressions (common in functional languages), then the order of evaluation has no value semantics – though it may yet bear on whether an infinite recursion terminates, or have other performance implications (in a functional language with match expressions, short-circuit evaluation is inherent, and natural uses for the ternary operator arise less often, so this point is of limited concern).
For these reasons, in some languages the statement form r = condition ? expr1 : expr2 can have subtly different semantics than the block conditional form if (condition) { r = expr1; } else { r = expr2; }.
In almost all languages, the ternary operator is right associative, so that a == 1 ? "one" : a == 2 ? "two" : "many" evaluates intuitively as a == 1 ? "one" : (a == 2 ? "two" : "many"). This means it can be chained similarly to an if ... else if ... else if ... else chain. The main exception is PHP, in which it was left-associative (such that the same expression evaluates to (a == 1 ? "one" : a == 2) ? "two" : "many", which is rarely what the programmer expects)[3] prior to version 8, and is non-associative thereafter.[4]
Furthermore, in all C-family languages and many others, the ternary conditional operator has low operator precedence.
The 2012 edition of Ada introduced conditional expressions (using if and case), as part of an enlarged set of expressions including quantified expressions and expression functions. The Rationale for Ada 2012[5] states motives for Ada not having had them before, as well as motives for now adding them, such as to support "contracts" (also new).
Pay_per_Hour := (if Day = Sunday then 12.50 else 10.00);
When the value of an if_expression is itself of Boolean type, then the else part may be omitted, the value being True. Multiple conditions may chained using elsif.
ALGOL 60 introduced conditional expressions (ternary conditionals) to imperative programming languages.
This conditional statement:
integer opening_time;
if day = Sunday then
opening_time := 12;
else
opening_time := 9;
Can be rewritten with the conditional operator:
integer opening_time;
opening_time := if day = Sunday then 12 else 9;
Both ALGOL 68's choice clauses (if and case clauses) support the following:
if condition then statements [ else statements ] fi or a brief form: ( condition | statements | statements )if condition1 then statements elif condition2 then statements [ else statements ] fi or a brief form: ( condition1 | statements |: condition2 | statements | statements ).A true ternary operator exists for arithmetic expressions:
((result = condition ? value_if_true : value_if_false))
For strings there are workarounds, like e.g.:
result=$(if condition ; then echo "value_if_true" ; else echo "value_if_false" ; fi)
Where condition can be any bash command. When it exits with success, the first echo command is executed, otherwise the second one is executed.
The following code in C assigns result to the value of x if a > b, and otherwise to the value of y. This is the same syntax as in many related languages including C++, Java, JavaScript, and Dart.
result = a > b ? x : y;
Only the selected expression is evaluated. In this example, x and y require no evaluation, but they can be expressions with side effects. Only the side-effect for the selected expression value will occur.[6][7]
If x and y are of the same data type, the conditional expression generally has that type. Otherwise, the rules governing the resulting data type vary a little between languages:
x and y to a common type. If both are pointer or reference types, or one is a pointer type and the other is a constant expression evaluating to 0, pointer or reference conversions are performed to convert them to a common type.[8]Furthermore, in C++, a conditional expression can be used as an lvalue, if both x and y are lvalues, though this is rarely used in practice:[10]
(foo ? bar : baz) = frink;
Assignment using a conditional expression in Common Lisp:
(setq result (if (> a b) x y))
Alternative form:
(if (> a b)
(setq result x)
(setq result y))
In dBase, the conditional function iif(<expL>, <expT>, <expF>) is called "Immediate IF". It uses shortcut evaluation (it only evaluates one of <expT> or <expF>).
For example, to sort a list by the street name and then (in most cases) house number, one could type
index on iif(instr(addr," ") , substr(addr,instr(addr," ")+1,10) + left(addr,instr(addr," ")-1) , addr) to indexfile
at the dBASE III command prompt, and then copy or export the table.
As part of the Fortran-90 Standard, the ternary operator was added to Fortran as the intrinsic function merge:
variable = merge(x,y,a>b)
Note that both x and y are evaluated before the results of one or the other are returned from the function. Here, x is returned if the condition holds true and y otherwise.
Fortran-2023 added conditional expressions which evaluate one or the other of the expressions based on the conditional expression:
variable = ( a > b ? x : y )
Kotlin does not include the traditional ?: ternary operator, however, an if can be used as an expression that can be assigned,[11] achieving the same results.
val max = if (a > b) a else b
Lua does not have a traditional conditional operator. However, the short-circuiting behavior of its and and or operators allows the emulation of this behaviour. The following is equivalent to: var = cond ? a : b.
var = cond and a or b
This will succeed unless a is logically false; in this case, the expression will always result in b. This can result in some surprising behavior if ignored.
There are also other variants that can be used, but they're generally more verbose:
var = (
{
[true] = a,
[false] = b
}
)[not not cond]
Luau, a dialect of Lua, has ternary expressions that look like if statements, but unlike them, they have no end keyword, and the else clause is required. One may optionally add elseif clauses. It's designed to replace the cond and a or b idiom and is expected to work properly in all cases.[12]
-- in Luau
var = if cond then a else b
-- with elseif clause
sign = if var < 0 then -1 elseif var == 0 then 0 else 1
Pascal was both a simplification and extension of ALGOL 60, but it removed conditional expressions.
RemObjects Oxygene added a ternary operator to Object Pascal in approximately 2011,[13] and in 2025 Delphi followed suit.[14] Oxygene supports case/switch statements, essentially a repeated if, as expressions evaluating to a value as well.[15]
Python has had a ternary conditional expression since release 2.5 (September 2006).[16] Python's conditional operator differs from the C-style ?: operator in the order of its operands. The general form is:[17]
result = x if a > b else y
This form invites considering x as the normal value and y as an exceptional case. Unlike Python conditional statements, the elif clause is not supported, but nested conditional expressions are allowed.
Ruby has supported the ?: conditional operator since its first public release (version 0.95, December 1995), inheriting the syntax from Perl and C. Because Ruby is a purely expression-based language - every construct, including if/else, returns a value - the ternary operator is not strictly necessary, but it is idiomatic and preferred by the Ruby Style Guide[18] for concise single-line conditional assignments.
status = age >= 18 ? "adult" : "minor"
Ruby's ? token is also used as a suffix on predicate method names (e.g. logged_in?), which can produce a visually ambiguous double question mark when such a method is used as the condition:
greeting = logged_in? ? "Welcome back!" : "Please sign in."
The community style guide recommends using spaces around both ? and :, keeping each branch to a single expression. Nested ternary operators should be avoided — preferring if/elsif/else in those cases. Multi-line ternary expressions are also discouraged; a multi-line if/else block is preferred instead.[19]
As an expression-oriented programming language, all Rust conditionals are expressions, not statements, so the if expr1 else expr2 syntax behaves like the C-style ?: ternary operator. Earlier versions of the language had a ?: operator but it was removed[20] due to duplication with if.[21]
Note the lack of semi-colons in the code below compared to an imperative if...else block, and the semi-colon at the end of the assignment to y.
let x = 5;
let y = if x == 5 {
10
} else {
15
};
This could also be written as:
let y = if x == 5 { 10 } else { 15 };
Curly braces are mandatory in Rust conditional expressions.
You could also use a match expression:
let y = match x {
5 => 10,
_ => 15,
};
Every expression (message send) has a value. Thus ifTrue:ifFalse: can be used:
|x y|
x := 5.
y := (x == 5) ifTrue:[10] ifFalse:[15].
The SQL CASE expression is a generalization of the ternary operator. Instead of one conditional and two results, n conditionals and n+1 results can be specified.
With one conditional it is equivalent (although more verbose) to the ternary operator:
SELECT (CASE WHEN a > b THEN x ELSE y END) AS CONDITIONAL_EXAMPLE
FROM tab;
This can be expanded to several conditionals:
SELECT (CASE WHEN a > b THEN x WHEN a < b THEN y ELSE z END) AS CONDITIONAL_EXAMPLE
FROM tab;
Visual Basic provides a ternary conditional function, IIf, as shown in the following code:
Dim opening_time As Integer = IIf((day = SUNDAY), 12, 9)
As a function, the values of the three arguments are evaluated before the function is called. To avoid evaluating the expression that is not selected, the If keyword was added (in Visual Basic .Net 9.0) as a true ternary conditional operator. This allows the following code to avoid an exception if it were implemented with IIf instead:
Dim name As String = If(person Is Nothing, "", person.Name)
Source: Wikipedia. Article content is retrieved live through the MediaWiki API.
In computer programming, the ternary conditional operator is a conditional expression with three parts: the Boolean condition, the then-expression, and the else-expression. If the condition is true, the then-expression is evaluated; otherwise, the else-expression is evaluated; and the value is returned. Thus it is a non-strict operator, like other conditional expressions. It is also called a conditional operator, ternary if, immediate if, or inline if (iif). Although a ternary operator in general is any operator with three arguments, the three-argument conditional operator is the only common one in programming, so it is loosely called the ternary operator. C introduced the syntax a ? b : c, read as "if a then b otherwise c", which is widely used by other languages with C-like syntax. Some languages use functional syntax: in Visual Basic, it is written If(a, b, c). Many languages support conditional expressions with two, three, or more clauses. Languages following ALGOL-like syntax often support them with the same syntax as conditional statements, if a then b else c. The construct first appeared in CPL in 1963, as a → b, c.
In mathematics, a ternary operation is an n-ary operation with n = 3. A ternary operation on a set A takes any given three elements of A and combines them to form a single element of A. In computer science, a ternary operator is an operator that takes three arguments as input and returns one output.
In certain computer programming languages, the Elvis operator, often written ?:, is a binary operator that returns the first operand if its value is logically true (according to a language-dependent convention, in other words, a truthy value) or returns its second operand if the first operand is not true. That is, it is a short-circuit OR, which returns its first truthy operand. The syntax of the Elvis operator was inspired by the ternary conditional operator, ? :, since the Elvis operator expression A ?: B is approximately equivalent to the ternary conditional expression A ? A : B. It is called the "Elvis operator" because the notation ?:, when viewed sideways, resembles an emoticon of Elvis Presley with his signature hairstyle. A similar operator is the null coalescing operator, where the boolean truth(iness) check is replaced with a check for non-null instead. This is usually written ??, and can be seen in languages like C# or Dart.
In computer programming, an operator is a programming language construct that provides functionality that may not be possible to define as a user-defined function (e.g. sizeof in C) or has syntax different from that of a function (e.g. infix addition as in a+b). Like other programming language concepts, operator has a generally accepted, although debatable, meaning among practitioners. Some operators are represented with symbols – characters typically not allowed for a function identifier – to allow for presentation that is more familiar looking than typical function syntax. For example, a function that tests for greater-than could be named gt, but many languages provide an infix symbolic operator so that code looks more familiar. For example, this: if gt(x, y) then return Can be: if x > y then return Some languages allow a language-defined operator to be overridden with user-defined behavior and some allow for user-defined operator symbols. Operators may also differ semantically from functions. For example, short-circuit Boolean operations evaluate later arguments only if earlier ones are not false.
Before the 1921 destruction of Tulsa’s Greenwood District, Black residents had created a remarkable center of business and community life. The district included stores, professional offices, entertainment venues and homes owned by Black citizens. Understanding Greenwood means learning what was built—not only what was burned.
MORE →Brown v. Board of Education in 1954.