Conditional

In a conditional statement or expression the value of a condition determines which alternative pieces of code to execute.

Related concepts:  StatementExpressionControl Flow

Closest Wikipedia entry:  Conditional (computer programming) — In computer science, conditionals (that is, conditional statements, conditional expressions and conditional constructs) are programming language constructs that perform different computations or actions or return different values depending on the value of a Boolean expression, called a condition. Conditionals are typically implemented by selectively executing instructions. Although dynamic dispatch is not usually classified as a conditional construct, it is another way to select between alternatives at runtime.

Misconceptions about Conditional
23 documented Misconceptions

Check Yourself
Misconception
BaseCaseNotNeededJava
Recursive computations do not necessarily need a base case
Misconception
BaseCaseNotNeededScratch
Recursive computations do not necessarily need a base case
Misconception
ConditionOneOutEdgeJava
A condition node in a control-flow graph can have a single outgoing edge
Misconception
ConditionalIsSequenceJava
If-else is equivalent to sequence of two ifs
Misconception
ConditionalIsSequencePython
If-else is equivalent to sequence of two ifs
Misconception
ConditionalIsSequenceScratch
If-then-else block is equivalent to sequence of two if-then blocks
Misconception
ConditionalOperatorNotExpressionJavaScript
The conditional operator is not an expression
Misconception
ElsIfJava
There is an elsif keyword for multi-way conditional statements
Misconception
ElseAlwaysExecutesJava
The else branch of an if-else statement always executes
Misconception
ElseAlwaysExecutesScratch
The else branch of an if-then-else block always executes
Misconception
ForIsConditionalJava
The body of a for statement executes at most once
Misconception
IfIsLoopJava
The body of an if statement executes repeatedly, as long as the condition holds
Misconception
IfIsLoopPython
The body of an if-statement executes repeatedly, as long as the condition holds
Misconception
IfRequiresElseJava
Every if statement requires an else
Misconception
LoopTerminatingConditionJava
For and while loops end when the condition becomes true
Misconception
MapToBooleanWithConditionalOperatorJava
To map a boolean expression to a boolean, a conditional operator is necessary
Misconception
MapToBooleanWithIfJava
To map a boolean expression to a boolean, an if statement is necessary
Misconception
MapToBooleanWithIfPython
To map a boolean expression to a bool, an if statement is necessary
Misconception
MapToBooleanWithTernaryOperatorPython
To map a boolean expression to a bool, a ternary conditional operator is necessary
Misconception
MissingElseTerminatesScratch
Blocks following an if without else will not execute if the condition is false
Misconception
RecursiveFunctionNeedsIfElsePython
A recursive function needs to contain an if-else statement
Misconception
RecursiveMethodNeedsIfElseJava
A recursive method needs to contain an if-else statement
Misconception
StatementMultipleOutEdgesJava
A non-condition node in a control-flow graph can have multiple outgoing edges

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.