Comparison Operations: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(edit)
(edit)
Line 3: Line 3:
{|
{|
|-valign="top"
|-valign="top"
|width="10%"|'''Operator'''|| '''Meaning'''
|width="20%"|'''Operator'''|| '''Meaning'''
|-valign="top"
|-valign="top"
|width="10%"|'''='''||equal, like the '''==''' operator below
|width="20%"|'''='''||equal, like the '''==''' operator below
|-valign="top"
|-valign="top"
|width="10%"|'''=='''||equal
|width="20%"|'''=='''||equal
|-valign="top"
|-valign="top"
|width="10%"|'''<>'''||not equal
|width="20%"|'''<>'''||not equal
|-valign="top"
|-valign="top"
|width="10%"|'''<'''||less than
|width="20%"|'''<'''||less than
|-valign="top"
|-valign="top"
|width="10%"|'''<='''||less than or equal to
|width="20%"|'''<='''||less than or equal to
|-valign="top"
|-valign="top"
|width="10%"|'''>'''||more than
|width="20%"|'''>'''||more than
|-valign="top"
|-valign="top"
|width="10%"|'''>='''||more than or equal to
|width="20%"|'''>='''||more than or equal to
|}
|}
Consider the following example of how comparison operations may be used in a program:
00010 ! prompt user and read first number
00020 print "Enter first integer: "
00030 input number1
00040 ! prompt user and read second number
00050 print "Enter second integer: "
00060 input number2
00070 if number1 == number2 then print "number1 is equal to number2"
00080 if number1 <> number2 then print "number1 is not equal to number2"
00090 if number1 <  number2 then print "number1 is less than number2"
00100 if number1 >  number2 then print "number1 is more than number2"
00110 if number1 <= number2 then print "number1 is less than or equal to number2"
00120 if number1 >= number2 then print "number1 is more than or equal to number2"
<noinclude>
<noinclude>
[[Category:Operations]]
[[Category:Operations]]
[[Category:Comparison Operations]]
[[Category:Comparison Operations]]
</noinclude>
</noinclude>

Revision as of 13:09, 11 January 2012

Below is the list of comparison operators:

Operator Meaning
= equal, like the == operator below
== equal
<> not equal
< less than
<= less than or equal to
> more than
>= more than or equal to

Consider the following example of how comparison operations may be used in a program:

00010 ! prompt user and read first number
00020 print "Enter first integer: "
00030 input number1
00040 ! prompt user and read second number
00050 print "Enter second integer: "
00060 input number2
00070 if number1 == number2 then print "number1 is equal to number2"
00080 if number1 <> number2 then print "number1 is not equal to number2"
00090 if number1 <  number2 then print "number1 is less than number2"
00100 if number1 >  number2 then print "number1 is more than number2"
00110 if number1 <= number2 then print "number1 is less than or equal to number2"
00120 if number1 >= number2 then print "number1 is more than or equal to number2"