Home

ifthen

An if-then statement is a control-flow construct that evaluates a boolean condition and executes a block of statements when the condition is true. It is a basic mechanism for conditional execution and appears in many programming languages as well as in formal logic. If the condition is false, the program continues with the next statement, or follows an alternative path if an else branch is provided.

Origins and usage: Historically, forms of conditional branching appeared in early imperative languages such as Algol

Variants: most languages support an optional else-part to specify an alternate block when the condition is

Impact: The if-then construct is central to algorithm design, enabling branches, guards, and early exit patterns.

and
Fortran,
introducing
the
idea
of
a
test
followed
by
a
then-clause.
Different
languages
adopted
varying
syntax:
Pascal
uses
if
condition
then
and
begin...end
blocks;
Ada
uses
if
condition
then
...
elsif
...
then
...
else
...
end
if;
C-style
languages
implement
the
same
idea
with
if
(condition)
{
...
}
without
the
then
keyword.
In
some
functional
languages
the
conditional
is
an
expression
that
returns
a
value
rather
than
a
block
of
statements.
false;
many
also
provide
else-if
or
elsif
chains
for
multiple
branches.
Nested
if-then
constructs
enable
multi-level
decision
trees.
In
some
languages
conditional
expressions
enable
concise
forms
such
as
If(condition,
thenValue,
elseValue)
or
the
ternary
operator
condition
?
thenValue
:
elseValue,
though
these
are
typically
treated
as
expressions
rather
than
statements.
Its
clarity
and
readability
depend
on
consistent
style,
proper
indentation,
and
avoiding
excessive
nesting.
See
also:
conditional
expression,
switch/case
statement,
pattern
matching.