Professional Documents
Culture Documents
Decision Statements
If statement
If else statement
Nested If statement
Nested If-else statement
If statement
Syntax:
if(expression)
{
Statements
}
If Statement
If condition is true
statements
Flow line
Continuation mark
Decision
Flow Chart for if statement
Entry point for IF block
IF
Condition
Then
Process/
set of statement
AND &&
OR ||
Logical Operators
If a is greater than b
AND c is greater than d
In C
if(a > b && c> d)
if(age > 18 || height > 5)
If else statement
IF
Condition
Then
Process 1/
Set of statement
Else
Process 2
Set of statement
!true = false
!false = true
Example
If (AmirAge != AmaraAge)
cout << “Amir and Amara’s Ages
are not equal”;
If (!(AmirAge > AmaraAge))
?
Nested If statement
Syntax:
if (condition-1)
{
if (condition-2) {
Statements-2 }
Statement-3;
}
Nested If statement
Condition-1 is tested, if
true then control goes to
next “if statement” and
condition-2 is tested.
Syntax:
if (condition-1)
Statements-1;
else if (condition-2)
Statements-2;
else if (condition-3)
Statements-3;
--------
--------
else Statement –n;
Example
/* Make a program that take student grade & tells him else
what grade he/she has achieved?
if(marks>=80) {
Hint:Use Nestd if-else statement. Grade A (90-100),
Grade B (80-89),Grade C(70-79), Grade D (60-69), if cout<<"\nGrade ****B****\n"; }
marks are less than 60 (you should take this courese else
again)*/ if(marks>=70)
#include<iostream>
{
using namespace std;
cout<<"\nGrade ***C***\n";
main()
}
{ int marks=0;
cout<<"Please enter number obtained out of 100 =\n"; else
cin>>marks; if(marks>=60)
if(marks>100||marks<0) {
cout<<"marks should be greater than 0 and less than cout<<"\nGrade **D**\n";
100”;
}
if(marks>=90)
else
{ cout<<"\nGrade *****A*****\n"; }
cout<<"F\t\t\t You must take this
course again";