Skip to content

Conditional (Computer Programming)

A language construct selects a program branch or value by testing a condition and evaluating the selected alternative.

Version
v1 · 2026-10-03 · History
Domain-specific #
13077
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomain
Programming Language Semantics → Computer Science & Software Engineering
Aliases
Programming Conditional

Core Idea

A conditional evaluates a test and selects which program branch runs or which expression yields a value. In ordinary if and conditional-expression constructs, an unselected branch is skipped. This lets a test both choose behavior and guard operations that would be invalid in the other case.[1][2]

How would you explain it like I'm…

The Pick-a-Path Question

A computer can ask a question, like 'Is it raining?' If yes, it does one thing, like 'take an umbrella.' If not, it can do something else, or nothing. The path it didn't pick never happens at all.

Pick-a-Path Instruction

A conditional is a part of a program that checks something and then picks what to do or what answer to give. An 'if' can choose which group of instructions runs. The choice that isn't picked doesn't run at all, which is useful: it can stop the computer from trying something impossible, like dividing by zero, or from doing extra work. Different programming languages have their own rules, like what counts as 'false' and whether you must always give an 'else' choice.

Test-and-Select Branching

A conditional evaluates a test and selects which alternative to execute or which value to produce. An if statement chooses which block of statements runs, while a conditional expression chooses which expression's value becomes the result. In ordinary short-circuit conditionals, the unselected branch is never evaluated, so it can guard against an invalid operation, skip wasted work, or avoid a side effect. The idea is shared across languages, but the details differ: C treats zero as false, while Racket treats only #f as false. Racket's if requires an else part, but C's if may leave it out. So it's wrong to say every test is strictly Boolean or that every conditional has exactly two branches.

 

A conditional in a programming language evaluates a test and, based on the outcome, selects an alternative to execute or a value to produce. Statement forms like if choose a suite of statements; expression forms choose which subexpression's value becomes the result. The load-bearing property in ordinary conditionals is that the unselected alternative is not evaluated. That makes conditionals more than stylistic branching: they can prevent an invalid operation from being attempted, avoid unnecessary computation, and suppress side effects in the unused branch. The structure is common across languages but semantics differ. C's if treats a zero value as false and any nonzero as true, whereas in Racket only #f is false. Racket's if requires an else expression, while C's if statement may omit else. Describing all tests as Boolean expressions, or all conditionals as having exactly two executed alternatives, misstates such languages.

Scope of Application

Programming languages use conditionals in statements and expressions. The pattern has a test, alternatives and a language-defined selection rule. A statement chooses a continuation; an expression yields the chosen value. Details vary by language: C permits an if without else, while Racket's if expression requires both alternatives.[1][3]

Clarity

It is not logical material implication or a generic decision. It is not always a Boolean-typed test: C interprets zero and nonzero scalar results. A conditional expression can have side effects, and replacing it with an eager function may evaluate a branch that the original would skip.[1][2]

Manages Complexity

A C if/else chooses one action; C's condition ? value1 : value2 selects an expression's value; Racket's (if test then else) selects one required result branch. Each localizes a choice so downstream code need not treat both alternatives as simultaneously executed.[1][2][3]

Abstract Reasoning

To reason about a conditional, determine how the test is interpreted, which alternative is evaluated, and what continuation or value results. Then check whether the unselected branch is skipped under the language's actual rules; an eager substitute may change behavior.

Knowledge Transfer

Test-and-branch selection recurs across languages, but their truth conversion, evaluation order, optional branches and result typing do not transfer automatically. The receiving language's specification controls those details. Live Selection is the strict broader pattern; this construct adds operational branch evaluation.

Relationships to Other Abstractions

Local relationship map for Conditional (Computer Programming)Parents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Conditional (ComputerProgramming)DOMAINPrime abstraction: Selection — is a kind ofSelectionPRIME

Current abstraction Conditional (Computer Programming) Domain-specific

Parents (1) — outgoing typed relations

  • Conditional (Computer Programming) is a kind of Selection Prime

    A programming conditional selects which available branch or value passes according to a test.

Hierarchy path (1) — routes to 1 parentless root

  • Conditional (Computer Programming) → is a kind of Selection

Neighborhood in Abstraction Space

Conditional (Computer Programming) sits in a sparse region of the domain-specific corpus (64th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Logical Inference, Modality & Conditional Structures (28 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

References

[1] Microsoft Learn, C if Statement. registry ↩a ↩b ↩c ↩d

[2] Microsoft Learn, C Conditional-Expression Operator. registry ↩a ↩b ↩c

[3] Racket, Conditionals. registry ↩a ↩b