You are on page 1of 14

Programming Fundamentals

Lecture 4
by
Imran Kazmi
In the Previous Lecture
• Type Declaration Instructions
• Arithmetic Instructions
• Input / Output Instructions
• Control Instructions
Decision
Decision
• If the person’s age is equal to or greater than 18
years than he/she can apply for the driving
license.
• If the height of the player is not less than 6 ft
than he can join basket ball team.
• Minimum marks to qualify for the next class is
50%.
• Bonus is granted on minimum 5 years of service.
If Statement
If condition is true
statements

If Ali’s height is greater then 6 feet


Then
Ali can become a member of the Basket
Ball team
If Statement in C

If (condition)
statement ;
If Statement
If ( condition )
{
statement1 ;
statement2 ;
:
}
Relational Operators

It is use to compared value of two expressions depending on their relation.

< less than


<= less than or equal to
== equal to
>= greater than or equal to
> greater than
!= not equal to
Logical or Boolean Operator
• Operator used with one or more operand and
return either value zero (for false) or
• one (for true). The operand may be constant,
variables or expressions. And the
• expression that combines two or more
expressions is termed as logical expression.
• C++ has three logical operators :
Logical Operators

• && AND
• || OR
• ! NOT
• Where logical NOT is a unary operator and other two are
binary operator.
• Logical AND gives result true if both the conditions are
true, otherwise result is false. And logical OR gives result
false if both the condition false, otherwise result is true.
•Programming
Practice
if-else
if (condition)
{
statement ;
-
-
}
else
{
statement ;
-
-
}
if-else
Entry point for IF-Else block

IF

Condition

Then

Process 1

Else

Process 2

Exit point for IF block

Note indentation from left to right


• Programming practice

You might also like