What type of operator can be used to determine whether a specific relationship exists between two values?

If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Skip to content

Kenneth Leroy Busbee

Overview

A relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality [e.g., 5 = 5] and inequalities [e.g., 4 ≥ 3].[1]

Discussion

The relational operators are often used to create a test expression that controls program flow. This type of expression is also known as a Boolean expression because they create a Boolean answer or value when evaluated. There are six common relational operators that give a Boolean value by comparing [showing the relationship] between two operands. If the operands are of different data types, implicit promotion occurs to convert the operands to the same data type.

Operator symbols and/or names can vary with different programming languages. Most programming languages use relational operators similar to the following:

Operator Meaning
< less than
> greater than
= greater than or equal to
== equality [equal to]
!= or inequality [not equal to]

Examples:

  • 9 < 25
  • 9 < 3
  • 9 > 14
  • 9 = 25
  • 9 == 13
  • 9 != 13
  • 9 !< 25
  • 9 25

Note: Be careful. In math you are familiar with using the symbol = to mean equal and ≠ to mean not equal. In many programming languages the ≠ is not used and the = symbol means assignment.

Key Terms

relational operatorAn operator that gives a Boolean value by evaluating the relationship between two operands.

References

  • cnx.org: Programming Fundamentals – A Modular Structured Approach using C++

Addition [+]

Description
This operator provides the sums of two numbers. Basic arithmetic operator used for addition; the result of an arithmetic operator is usually a numeric value.

Syntax
[expression1] [expression2]

Comments
Although the + operator can be used to concatenate two character strings, the & operator should be used for concatenation to eliminate ambiguity and provide self-documenting code. If + operator is used, there may be no way to determine whether addition or string concatenation will occur. The underlying subtype of the expressions determines the behavior of the + operator in the following way:

If

Then

Both expressions are numeric Add
Both expressions are strings Concatenate
One expression is numeric and the other is a string Add

If one or both expressions are Null expressions, the result is Null. If both expressions are Empty, the result is an integer subtype. However, if only one expression is Empty, the other expression is returned unchanged as a result.

Example

READ {.ProjectsSampleSample.prj}:Oswego DEFINE Newvar NUMERIC ASSIGN Newvar = Age + 5 LIST Age Newvar

ARITHMETIC

Description
These basic arithmetic operators can be used in combination with other commands. The result is a numeric value.

Syntax
[Expression] [Expression]

  • [Expression] is a numeric value or a variable containing data in numeric format.

Comments
The results are expressed in numeric format. The basic mathematical operators that can be used in Epi Info are as follows:

  • Addition + Basic arithmetic operator used for addition; the result of an arithmetic operator is usually a numeric value [i.e., EX. 3 + 3].
  • Subtraction – [Used for subtraction or negation.] Basic arithmetic operator used for subtraction or negation; the result of an arithmetic operator is usually a numeric value [i.e., EX. 3 – 1].
  • Multiplication * [Asterisk] Basic arithmetic operator used for multiplication; the result of an arithmetic operator is usually a numeric value.
  • Division / Basic arithmetic operator used for division; the result of an arithmetic operator is usually a numeric value.
  • Exponentiation ^
  • Modulus or Remainder MOD

Arithmetic operators are shown in descending order of precedence. Parentheses can be used to control the order in which operators are evaluated. The default order, however, frequently achieves the correct result.

While it is possible to do date math with dates considered as a number of days [e.g., IncubationDays = SymptomDateTime – ExposureDateTime], the behavior of the database services underlying Epi Info makes it more efficient to use time interval functions [e.g., IncubationDays = MINUTES[ExposureDateTime, Symptom DateTime]/[24*60]]. For doing date math, the following rules apply:

Date + Date produces Date
Date – Date produces Days
Date * Date not permitted
Date / Date not permitted
Date ^ Date not permitted
Date + Number produces Date
Number + Date produces Number
The last two rules apply as well to other math operations: -, *, /, ^
The “zero day” for date math is December 30, 1899.

Example

READ {.ProjectsSampleSample.prj}:Surveillance DEFINE var1 NUMERIC ASSIGN var1=1250 MOD 100 DEFINE var2 NUMERIC ASSIGN var2=1+1 DEFINE var3 NUMERIC ASSIGN var3=2-1 DEFINE var4 NUMERIC ASSIGN var4=1*1 DEFINE var5 NUMERIC ASSIGN var5=8/4 DEFINE var6 NUMERIC ASSIGN var6=5^2 LIST var1 var2 var3 var4 var5 var6

Comparisons

Description
These comparison operators can be used in If, Then, and Select statements in Check Code and Analysis programs. Yes/No variables can only be tested for equality against other Yes/No constants [+], [-], and [.].

Operator

Description

= Equal to Comparison operator used for equal to; the result of comparison operators is usually a logical value, either True or False. EX. A1 = B1.
> Greater than comparison operator. Compares a value greater than another value; the result of comparison operators is usually a logical value, either True or False. Comparison operator used for comparing a value greater than another value; the result of comparison operators is usually a logical value, either True or False. EX. A1 > B1.
< Less than comparison operator. Compares a value less than another value; the result of comparison operators is usually a logical value, either True or False. Comparison operator used for comparing a value less than another value; the result of comparison operators is usually a logical value, either True or False. EX. A1= Greater than or equal to.
20 LIST Age Disease READ {.ProjectsSampleSample.prj}:Surveillance SELECT Age=38 LIST Age Disease READ {.ProjectsSampleSample.prj}:Surveillance SELECT Age77 LIST Age Disease

Which operators are used to determine whether a specific relationship exists between two variables?

Relational Operators determine whether a specific relationship exist between two values.

What type of operators are the following ==?

Relational Operators == [Equal to]– This operator is used to check if both operands are equal.

What are logical operators?

A logical operator is a symbol or word used to connect two or more expressions such that the value of the compound expression produced depends only on that of the original expressions and on the meaning of the operator. Common logical operators include AND, OR, and NOT.

Which of the following is a logical operator?

There are three logical operators: and , or , and not . The semantics [meaning] of these operators is similar to their meaning in English. For example, x > 0 and x < 10 is true only if x is greater than 0 and at the same time, x is less than 10.

Chủ Đề