0% found this document useful (0 votes)
32 views

Condition Statement and Basic Operators

Uploaded by

Romeo Bagunu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Condition Statement and Basic Operators

Uploaded by

Romeo Bagunu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

COMPUTER PROGRAMMING 1

CONDITION STATEMENT
Conditions are statements that result in a Boolean value. A
Boolean value may either be TRUE or FALSE. Conditions are logical
expressions. Logical expressions evaluate to a Boolean value. There
are two types of operators which provide Boolean values as results -
logical and relational.
Logical Operators are mainly used to control program flow. They
are usually part of an IF, WHILE, or some other control statements.
Logical operators allow a program to decide based on multiple
conditions.
Relational Operators are used to compare two operands and
determine the validity of a relationship.
BASIC LOGICAL OPERATION
NOT Operator (!)
The NOT truth table shows the nature of the NOT operator. A truth table is a
type of mathematical table used in logic to determine whether an expression is
true or valid. Such a table typically contains several rows and columns with the
top row representing the logical variables and combinations, in increasing
complexity leading up to the final function.
Basically, the NOT operator operates on a single value and the result is the
reverse of the operand Boolean value. Therefore, a TRUE will become FALSE and
a FALSE will become TRUE. Note that in flowcharting, TRUE may be represented
by T or 1 and FALSE may be represented by F or O.
Condition X !X
T F
F T
AND (&&)/OR (||) Operator
The AND and OR operators are commonly used operators in
conditions. The AND operator is used if you want a strict condition.
For AND to result to TRUE, both conditions must be satisfied. The
OR operator is used when either one of the conditions is true.
The truth table shows how the AND and OR operators’ function. For
the AND operator, the result will become TRUE if and only if both
conditions are TRUE, while the OR operator becomes TRUE if either
one or both conditions are TRUE.
Condition X Condition Y X AND Y X OR Y
T T T T
T F F T
F T F T
F F F F
RELATIONAL OPERATORS
The equality and relational operators determine the
relationship between the two operands. It checks if an
operand is greater than, less than, equal to, not equal to
and so on. Depending on the relationship, it is evaluated to
either true or false.
Operator Description Example
== equal to 5 == 3 is evaluated to false
!= not equal to 5 != 3 is evaluated to true
> greater than 5 > 3 is evaluated to true
< less than 5 < 3 is evaluated to false
>= greater than or equal to 5 >= 5 is evaluated to true
<= less than or equal to 5 <= 5 is evaluated to true

You might also like