Click to like/follow us on:

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
The sign ‘=’, ‘<’ and ‘>’ are called relational operators while X = Y, X < Y and X > Y are relational expressions.

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.
Example: If X = 20 and Y = 4. Then we will have the following code block for the above expressions.
  • if  X = Y then
    display “Hello”
        ...
    else
    display “Hi”
        ...
    end if
This word “if” trigger a test to know if 20 = 4. But the result in this case is “FALSE”, and because of this, “Hi” is displayed:
  • if  X < Y then
    display “Hello”
        ...
    else
    display “Hi”
        ...
    end if
Here a test is triggered to know if 20 < 4. The result again is “FALSE” and “Hi” is displayed. And now:
  • if  X > Y then
    display “Hello”
        ...
    else
    display “Hi”
        …
    end if
Here test is to know if 20 > 4. The result is “TRUE” and now “Hello” is displayed. It now follows that when the relational operators occurs in if statements, logical expression are called conditions and the if statement are called conditional statements.
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.
image

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.


SHARE THIS POST WITH YOUR FRIENDS...::

0 comments:

Leave a Reply

All Posts

Access all posts here!

Categories

Unordered List

Sample Text

Lists of Jobs in the United States

List of Courses & Outlines For UNN Students

Popular Posts

Like us on Facebook

Recent Posts

    Text Widget