Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Relational operator
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Standard relational operators== The most common numerical relational operators used in programming languages are shown below. Standard [[SQL]] uses the same operators as BASIC, while many databases allow <code>!=</code> in addition to <code><></code> from the standard. SQL follows strict [[boolean algebra]], i.e. doesn't use [[short-circuit evaluation]], which is common to most languages below. E.g. [[PHP]] has it, but otherwise it has these same two operators defined as aliases, like many SQL databases. {| class="wikitable" style="text-align: center;" |+ Common relational operators ! Convention ! ''equal to'' ! ''not equal to'' ! ''greater than'' ! ''less than'' ! ''greater than<br>or equal to'' ! ''less than<br>or equal to'' |- ! In print | = | β | > | < | β₯ | β€ |- ! [[FORTRAN]]<ref group="note">Including FORTRAN II, III, IV, 66 and 77.</ref> | <code>.EQ.</code> | <code>.NE.</code> | <code>.GT.</code> | <code>.LT.</code> | <code>.GE.</code> | <code>.LE.</code> |- ! rowspan=3 | [[ALGOL 68]]<ref group="note">[[ALGOL 68]]: ''[[Stropping (syntax)|stropping]]'' regimes are used in code on platforms with limited character sets (''e.g.'', use <code>>=</code> or <code>GE</code> instead of <code>β₯</code>), platforms with no <code>'''bold'''</code> [[Emphasis (typography)|emphasis]] (use <code>'ge'</code>), or platforms with only [[UPPERCASE]] (use <code>.GE</code> ''or'' <code>'GE'</code>).</ref> |rowspan=2| <code>=</code> | <code>β </code> |rowspan=2| <code>></code> |rowspan=2| <code><</code> | <code>β₯</code> | <code>β€</code> |- | <code>/=</code> | <code>>=</code> | <code><=</code> |- | <code>'''eq'''</code> | <code>'''ne'''</code> | <code>'''gt'''</code> | <code>'''lt'''</code> | <code>'''ge'''</code> | <code>'''le'''</code> |- ! [[APL (programming language)|APL]] | <code>=</code> | <code>β </code> | <code>></code> | <code><</code> | <code>β₯</code> | <code>β€</code> |- ! [[BASIC]], [[ML (programming language)|ML]], [[Pascal (programming language)|Pascal]]<ref group="note">Including [[ALGOL]], [[Simula]], [[Modula-2]], [[Eiffel (programming language)|Eiffel]], [[SQL]], [[spreadsheet formulas]], and others.</ref> | <code>=</code> | <code><></code><ref group="note">Modula-2 also recognizes <code>#</code></ref> | <code>></code> | <code><</code> | <code>>=</code> | <code><=</code> |- ! [[C (programming language)|C-like]]<ref group="note">Including [[C (programming language)|C]], [[C++]], [[C Sharp (programming language)|C#]], [[Go (programming language)|Go]], [[Java (programming language)|Java]], [[JavaScript]], [[Perl]] (numerical comparison only), [[PHP]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], and [[R (programming language)|R]].</ref> | <code>==</code> | <code>!=</code> | <code>></code> | <code><</code> | <code>>=</code> | <code><=</code> |- ! [[MUMPS]] | <code>=</code> | <code>'=</code> | <code>></code> | <code><</code> | <code>'<</code> | <code>'></code> |- ! [[Lua (programming language)|Lua]] | <code>==</code> | <code>~=</code> | <code>></code> | <code><</code> | <code>>=</code> | <code><=</code> |- ! rowspan="2" |[[Erlang (programming language)|Erlang]] |<code>==</code> |<code>/=</code> | rowspan="2" |<code>></code> | rowspan="2" |<code><</code> | rowspan="2" |<code>>=</code> | rowspan="2" |<code>=<</code> |- |<code>=:=</code> |<code>=/=</code> |- ! [[Unix shell#Bourne shell compatible|Bourne-like]] [[Shell (computing)|shells]]<ref group="note">Including [[Bourne shell]], [[Bash (Unix shell)|Bash]], [[KornShell]], and [[Windows PowerShell]]. The symbols <code><</code> and <code>></code> are usually used in a shell for [[Redirection (computing)|redirection]], so other symbols must be used. Without the hyphen, is used in [[Perl]] for string comparison.</ref> | <code>-eq</code> | <code>-ne</code> | <code>'''-gt'''</code> | <code>-lt</code> | <code>-ge</code> | <code>-le</code> |- ! [[Batch file]] | <code>EQU</code> | <code>NEQ</code> | <code>GTR</code> | <code>LSS</code> | <code>GEQ</code> | <code>LEQ</code> |- ! rowspan="3" |[[Object REXX|ooRexx]], [[Rexx|REXX]] | rowspan="3" |<code>=</code> |<code>Β¬=</code> | rowspan="3" |<code>></code> | rowspan="3" |<code><</code> | rowspan="3" |<code>>=</code> | rowspan="3" |<code><=</code> |- |<code>\=</code> |- |<code><></code> |- ! rowspan="2" |[[MATLAB]]<ref group="note">MATLAB, although in other respects using similar syntax as C, does not use <code>!=</code>, as <code>!</code> in MATLAB sends the following text as a command line to the [[operating system]]. The first form is also used in [[Smalltalk]], with the exception of equality, which is <code>=</code>.</ref> | <code>==</code> | <code>~=</code> | <code>></code> | <code><</code> | <code>>=</code> | <code><=</code> |- | <code>eq(x,y)</code> | <code>ne(x,y)</code> | <code>gt(x,y)</code> | <code>lt(x,y)</code> | <code>ge(x,y)</code> | <code>le(x,y)</code> |- ! [[Fortran 90]],<ref group="note">Including FORTRAN 95, 2003, 2008 and 2015.</ref> [[Haskell (programming language)|Haskell]] | <code>==</code> | <code>/=</code> | <code>></code> | <code><</code> | <code>>=</code> | <code><=</code> |- ! rowspan="2" |[[Mathematica]]<ref>[http://reference.wolfram.com/mathematica/tutorial/RelationalAndLogicalOperators.html Relational and Logical Operators] of [[Mathematica]]</ref> | <code>==</code> | <code>!=</code> | <code>></code> | <code><</code> | <code>>=</code> | <code><=</code> |- | <code>Equal[x,y]</code> | <code>Unequal[x,y]</code> | <code>Greater[x,y]</code> | <code>Less[x,y]</code> | <code>GreaterEqual[x,y]</code> | <code>LessEqual[x,y]</code> |} {{Reflist|group="note"}} Other conventions are less common: [[Common Lisp]] and [[Macsyma]]/[[Maxima (software)|Maxima]] use Basic-like operators for numerical values, except for inequality, which is <code>/=</code> in Common Lisp and <code>#</code> in Macsyma/Maxima. Common Lisp has multiple other sets of equality and relational operators serving different purposes, including <code>eq</code>, <code>eql</code>, <code>equal</code>, <code>equalp</code>, and <code>string=</code>.<ref>{{cite web |title=Why are there so many ways to compare for equality? |url=https://stackoverflow.com/a/24032576/339482 |website=Stack Overflow |access-date=25 July 2024}}</ref> Older [[Lisp (programming language)|Lisps]] used <code>equal</code>, <code>greaterp</code>, and <code>lessp</code>; and negated them using <code>not</code> for the remaining operators.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)