Computational constructsLogical comparisons

Programs run in sequences. Selection statements and loops are used in programs, allowing software to make decisions and repeat actions. These are called computational constructs

Part ofComputing ScienceSoftware design and development

Logical comparisons

The previous program checked to see if the age value was above or below a certain value. Logical comparisons can be used to do this.

OperatorExplanationExample
<
Less than
age < 18
>
More than
age > 18
Less than or equal to (sometimes shown as <=)
age ≤ 18
More than or equal to (sometimes shown as >=)
age ≥ 18
=
Equality
age = 18
Inequality/Not equal to
age ≠ 18
Operator
<
ExplanationLess than
Example
age < 18
Operator
>
ExplanationMore than
Example
age > 18
Operator
ExplanationLess than or equal to (sometimes shown as <=)
Example
age ≤ 18
Operator
ExplanationMore than or equal to (sometimes shown as >=)
Example
age ≥ 18
Operator
=
ExplanationEquality
Example
age = 18
Operator
ExplanationInequality/Not equal to
Example
age ≠ 18

Using logical comparisons means you can check if a variable contains a value that meets, or doesn't meet, a certain condition. They are very useful when you are using conditional statements, such as if statements.