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
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.
Operator
Explanation
Example
<
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
<
Explanation
Less than
Example
age < 18
Operator
>
Explanation
More than
Example
age > 18
Operator
≤
Explanation
Less than or equal to (sometimes shown as <=)
Example
age ≤ 18
Operator
≥
Explanation
More than or equal to (sometimes shown as >=)
Example
age ≥ 18
Operator
=
Explanation
Equality
Example
age = 18
Operator
≠
Explanation
Inequality/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.