Category:Comparison Operations: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
|width="20%"|'''Operator'''|| '''Meaning''' | |width="20%"|'''Operator'''|| '''Meaning''' | ||
|-valign="top" | |-valign="top" | ||
|width="20%"|'''='''||equal, | |width="20%"|'''='''||equal (assignment), may also be used for comparisons in some situations | ||
|-valign="top" | |-valign="top" | ||
|width="20%"|'''=='''||equal | |width="20%"|'''=='''||equal (comparison) | ||
|-valign="top" | |-valign="top" | ||
|width="20%"|'''<>'''||not equal | |width="20%"|'''<>'''||not equal | ||
Line 19: | Line 19: | ||
|width="20%"|'''>='''||more than or equal to | |width="20%"|'''>='''||more than or equal to | ||
|} | |} | ||
===Example 1=== | |||
Consider the following example of how comparison operations may be used in a program: | Consider the following example of how comparison operations may be used in a program: | ||
Line 35: | Line 37: | ||
00120 if number1 >= number2 then print "number1 is more than or equal to number2" | 00120 if number1 >= number2 then print "number1 is more than or equal to number2" | ||
===Example 2 - Ilusetrate the difference between == and = === | |||
To illustrate the difference between == and =, look at the following program. You will see the values passed to the function from (A==B) and (A=B) are 0 and 7. (A==B) is a *comparison* and will return 1 or 0 for True or False, while (A=B) is a *assignment* and assigns A the value of B. | |||
Sample Program: | |||
A=5 | |||
B=7 | |||
fn_test(A,B,(A==B)) | |||
fn_test(A,B,(A=B)) | |||
en | |||
def fn_test(a,b,c) | |||
pr 'a=';a;'b=';b;'c=';c | |||
fn | |||
Sample Results: | |||
a= 5 b= 7 c= 0 | |||
a= 7 b= 7 c= 7 | |||
<noinclude> | <noinclude> | ||
[[Category:Operations]] | [[Category:Operations]] | ||
</noinclude> | </noinclude> |
Latest revision as of 17:30, 11 April 2018
Below is the list of comparison operators:
Operator | Meaning |
= | equal (assignment), may also be used for comparisons in some situations |
== | equal (comparison) |
<> | not equal |
< | less than |
<= | less than or equal to |
> | more than |
>= | more than or equal to |
Example 1
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"
Example 2 - Ilusetrate the difference between == and =
To illustrate the difference between == and =, look at the following program. You will see the values passed to the function from (A==B) and (A=B) are 0 and 7. (A==B) is a *comparison* and will return 1 or 0 for True or False, while (A=B) is a *assignment* and assigns A the value of B.
Sample Program:
A=5 B=7 fn_test(A,B,(A==B)) fn_test(A,B,(A=B)) en def fn_test(a,b,c) pr 'a=';a;'b=';b;'c=';c fn
Sample Results:
a= 5 b= 7 c= 0 a= 7 b= 7 c= 7
This category currently contains no pages or media.