1. Basic Computer Logical Operations:
A logical operation is an operation that follows the rules of symbolic logic. A logical operation is also known as Boolean operation is an action which is performed on one or two values know as the operand(s), to obtain a logical value. The logical value can either be “True” or “False” . Logical operation include OR, AND, NOT, etc.In an algorithm, logical operations are usually triggered by the word”if”.
If two numeric variables represented as X and Y, the possible logical relationship that may exist between these variables are as follows:
- X = Y
X < Y
X > Y
A relational operation requires the CPU to:
- i. Perform a test to see of the relationship exist on between operands such as X and Y.
ii. Accept the value TRUE if the operands are in the relation indicated in the expression.
- if X = Y then
display “Hello”
...
else
display “Hi”
...
end if
- if X < Y then
display “Hello”
...
else
display “Hi”
...
end if
- if X > Y then
display “Hello”
...
else
display “Hi”
…
end if
Example:
If X = 20
1. Because the relational operator ‘=’is exit in the expression then we can say that this is a condition.
2. The if statement can be called conditional statement.
But X = 20 Is not a condition. Why? Because there is absent of condition word (statement e.g if) and similarly X + 20 is not a condition.
Some relations operators are:
Take X = 20 and Y = 4.
= “equal to; e.g. X = Y result is FALSE
> “greater than”; e.g. X > Y result is TRUE
< “less than”; e.g. X < Y result is FALSE
>= “greater than or equal to”; e.g. X >= Y result is TRUE
=< “less than or equal to; e.g. X =< Y result is FALSE
<> “not equal to; e.g. X = Y result is TRUE
!= “not equal to”; e.g. X = Y result is FALSE
2. Basic Computer Decision, Transfer of Control Operation:
Computer solve problem sequentially. This means that the flow of action in an algorithm is downward. A conditional statement(s) may require a computer to transfer control (action) from the position (step) to another specified position(s) (step(s)) and resume back to the step where the transfer was made, after the execution of those steps it was transferred to, is complete.Example One:You are the pilot of an airplane, traveling to United State,
if (you have yellow card) then
change you destination to be Malaysia.
Land when you reach.
Of course the last line says “Land …” I know if had not include it, you the pilot might not know that you suppose to land when have reached your destination.
Example Two:10 increment laptop by 2
if (Age > 30 ) then
goto 10
Show laptop
Here a test will be carried out to see if Age is > 30. If the result is TRUE that “Age is greater than 30”, execution goes away (is transferred) to continue from step 1 labeled as 10. If the conditional statement “if Age > 30), is “FALSE” then the “goto 10” statement will transfer action or execution to the first line labeled 10.
The Age is greater than 30, (i.e is TRUE) so therefore transfer of control did not occur and by now I don’t need to tell you that will be displayed is 52.
And now this one is for you, do it alone:
10 decrement laptop by 7
if (Age > 18 ) then
goto 10
Print laptop
For questions/answers make use of the comment box below.
Previous: Basic Computer Output & Arithmetic Operations | Next: Basic Computer Assignment & Termination Operations
SHARE THIS POST WITH YOUR FRIENDS...::
Tweet
0 comments:
Leave a Reply