SlideShare a Scribd company logo
Control
statement
(if…. else)
MD. SHOHEL ARMAN
DEPT. OF SOFTWARE ENGINEERING
Algorithm
•The solution of any computing problem involves a series of action in a specific order.
•This procedure of solving problems is called algorithm.
Pseudocode
•Pseudocode is an outline of a program, written in a form that can easily be converted into real programming statements
•Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules
•It is simply one step - an important one - for producing the final code
•The benefit of pseudocode is that it enables the programmer to concentrate on the algorithms without worrying about all
the syntactic details of a particular programming language
•You can write pseudocode without even knowing what programming language you will use for the final implementation
if statement
Many times we have to take actions based on certain conditions. C provides if or if else statement
to allow us to execute statements based on conditions.
The if statement may be implemented in different forms depending on the complexity of the
conditions to be tested. The forms are:
1. Simple if statement
2. If……… else statements
3. Nested if ……else statements
4. else if ladder
Forms of if…. else Statements
❑Simple if statement:
if ( test expression)
{
Statement block;
}
❑if…else statement:
if ( test expression)
{
Statement block;
}
else
{
Statement block;
}
❑nested if…else statement:
if ( test expression)
{
if ( test expression)
Statement block;
else
Statement block;
}
else
{
statement block;
}
❑if…else ladder:
if ( test expression)
statement-1;
else if ( test expression)
Statement-2;
else if(test expression)
Statement-3;
else
statement-4;
Before going farther we need to review the Relational Operators and Logical Operators :
Relational Operators Logical Operators
C has following logical operators:
• AND expressed by &&
• OR expressed by ||
• NOT expressed by !
Pseudocode
//grade greater then 40 print pass else print failed:
………..
if (grade>40)
{
printf (“Passed n”);
}
Else
{
printf (“Failed n”);
}
……..
Simple if Statement
A simple if structure is used to choose among alternative courses of action
if student’s grade is more than 40
print “passed”
next pseudocode statement
In this pseudocode, if grade of a student is more than 40 then the print command will be
executed. Otherwise, if the student’s grade is not more than 40, the compiler will move to next
pseudocode statement
Simple if Statement
So, as a general form, we can see the if selection or simple if structure as-
if (condition){
body of if
}
The condition needs to be true to get into the body of if. Otherwise, the compiler will go to the next segment of codes
The pseudocode can be written in C as-
if (grade>40){
printf (“Passed n”);
}
If…else Statement
he if…else structure allows the programmer to specify that different actions are to be performed when
the condition is true and when the condition is false
if student’s grade is more than 40
print “passed”
else
print “failed”
If the condition of if is true, then compiler will print passed and if the condition of if is false, the
compiler will print failed.
If…else Statement
So, as a general form, we can see the if/else selection structure as-
if (condition){
body of if
}
else{
body of else
}
If…else Statement
The pseudocode can be written in C as-
if (grade>40)
{
printf (“Passed n”);
}
Else
{
printf (“Failed n”);
}
❑An if structure may not have any else statement followed by it but an else structure must have a if structure preceded.
Algorithm:
if student’s grade is more than 90
print “Grade: A”
else
if student’s grade is more than 80
print “Grade: B”
else
if student’s grade is more than 70
print “Grade: C”
else
if student’s grade is more than 60
print “Grade: D”
else
if student’s grade is more than 50
print “Grade: E”
else
print “Grade: F”
Using if…else statement
C-code:
#include<stdio.h>
void main(){
int grade;
printf("Enter your grade: ");
scanf("%d",&grade);
if (grade>90)
printf("Grade: A");
else if (grade>80)
printf("Grade: B");
else if (grade>70)
printf("Grade: C");
else if (grade>60)
printf("Grade: D");
else if (grade>50)
printf("Grade: E");
else
printf("Grade: F");
getch();

More Related Content

PPT
Chapter 4 flow control structures and arrays
PPTX
Control Statement programming
PPTX
week 3 Programming lecture 05 (1) j.pptx
PPT
Lec 04. If-Else Statement / Increment and Decrement Operators
PDF
ICP - Lecture 7 and 8
PPTX
Decision Control Structure If & Else
PDF
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
PPT
9781439035665 ppt ch04
Chapter 4 flow control structures and arrays
Control Statement programming
week 3 Programming lecture 05 (1) j.pptx
Lec 04. If-Else Statement / Increment and Decrement Operators
ICP - Lecture 7 and 8
Decision Control Structure If & Else
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
9781439035665 ppt ch04

Similar to conditional_statement.pdf (20)

PPTX
COM1407: Program Control Structures – Decision Making & Branching
PPTX
3. Java Installations ppt for engineering
PPTX
Control Statements -if else in C programming.pptx
PPTX
APP_Unit 1_updated.pptx
PDF
Programming Fundamentals Decisions
PDF
Control structure and Looping statements
PDF
CP Handout#4
PPTX
Java Decision Control
PPT
9781111530532 ppt ch04
PPT
9781111530532 ppt ch04
PPT
Visula C# Programming Lecture 3
PPTX
Constructs (Programming Methodology)
PPT
Ap Power Point Chpt3
PPTX
programming c language.
PPTX
Decision statements in vb.net
PPT
Chapter 1 nested control structures
PPT
03a control structures
PPTX
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
PPTX
Unit-02 Selection, Mathematical Functions and loops.pptx
PPT
The Three Basic Selection Structures in C++ Programming Concepts
COM1407: Program Control Structures – Decision Making & Branching
3. Java Installations ppt for engineering
Control Statements -if else in C programming.pptx
APP_Unit 1_updated.pptx
Programming Fundamentals Decisions
Control structure and Looping statements
CP Handout#4
Java Decision Control
9781111530532 ppt ch04
9781111530532 ppt ch04
Visula C# Programming Lecture 3
Constructs (Programming Methodology)
Ap Power Point Chpt3
programming c language.
Decision statements in vb.net
Chapter 1 nested control structures
03a control structures
Metode Perancangan Program #2 Selection and Repetition Control Structure-ITSB...
Unit-02 Selection, Mathematical Functions and loops.pptx
The Three Basic Selection Structures in C++ Programming Concepts

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Pre independence Education in Inndia.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
master seminar digital applications in india
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
GDM (1) (1).pptx small presentation for students
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
RMMM.pdf make it easy to upload and study
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPH.pptx obstetrics and gynecology in nursing
Pre independence Education in Inndia.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Anesthesia in Laparoscopic Surgery in India
VCE English Exam - Section C Student Revision Booklet
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Types and Its function , kingdom of life
Module 4: Burden of Disease Tutorial Slides S2 2025
master seminar digital applications in india
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
GDM (1) (1).pptx small presentation for students
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
STATICS OF THE RIGID BODIES Hibbelers.pdf

conditional_statement.pdf

  • 1. Control statement (if…. else) MD. SHOHEL ARMAN DEPT. OF SOFTWARE ENGINEERING
  • 2. Algorithm •The solution of any computing problem involves a series of action in a specific order. •This procedure of solving problems is called algorithm.
  • 3. Pseudocode •Pseudocode is an outline of a program, written in a form that can easily be converted into real programming statements •Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules •It is simply one step - an important one - for producing the final code •The benefit of pseudocode is that it enables the programmer to concentrate on the algorithms without worrying about all the syntactic details of a particular programming language •You can write pseudocode without even knowing what programming language you will use for the final implementation
  • 4. if statement Many times we have to take actions based on certain conditions. C provides if or if else statement to allow us to execute statements based on conditions. The if statement may be implemented in different forms depending on the complexity of the conditions to be tested. The forms are: 1. Simple if statement 2. If……… else statements 3. Nested if ……else statements 4. else if ladder
  • 5. Forms of if…. else Statements ❑Simple if statement: if ( test expression) { Statement block; } ❑if…else statement: if ( test expression) { Statement block; } else { Statement block; } ❑nested if…else statement: if ( test expression) { if ( test expression) Statement block; else Statement block; } else { statement block; } ❑if…else ladder: if ( test expression) statement-1; else if ( test expression) Statement-2; else if(test expression) Statement-3; else statement-4;
  • 6. Before going farther we need to review the Relational Operators and Logical Operators : Relational Operators Logical Operators C has following logical operators: • AND expressed by && • OR expressed by || • NOT expressed by !
  • 7. Pseudocode //grade greater then 40 print pass else print failed: ……….. if (grade>40) { printf (“Passed n”); } Else { printf (“Failed n”); } ……..
  • 8. Simple if Statement A simple if structure is used to choose among alternative courses of action if student’s grade is more than 40 print “passed” next pseudocode statement In this pseudocode, if grade of a student is more than 40 then the print command will be executed. Otherwise, if the student’s grade is not more than 40, the compiler will move to next pseudocode statement
  • 9. Simple if Statement So, as a general form, we can see the if selection or simple if structure as- if (condition){ body of if } The condition needs to be true to get into the body of if. Otherwise, the compiler will go to the next segment of codes The pseudocode can be written in C as- if (grade>40){ printf (“Passed n”); }
  • 10. If…else Statement he if…else structure allows the programmer to specify that different actions are to be performed when the condition is true and when the condition is false if student’s grade is more than 40 print “passed” else print “failed” If the condition of if is true, then compiler will print passed and if the condition of if is false, the compiler will print failed.
  • 11. If…else Statement So, as a general form, we can see the if/else selection structure as- if (condition){ body of if } else{ body of else }
  • 12. If…else Statement The pseudocode can be written in C as- if (grade>40) { printf (“Passed n”); } Else { printf (“Failed n”); } ❑An if structure may not have any else statement followed by it but an else structure must have a if structure preceded.
  • 13. Algorithm: if student’s grade is more than 90 print “Grade: A” else if student’s grade is more than 80 print “Grade: B” else if student’s grade is more than 70 print “Grade: C” else if student’s grade is more than 60 print “Grade: D” else if student’s grade is more than 50 print “Grade: E” else print “Grade: F” Using if…else statement C-code: #include<stdio.h> void main(){ int grade; printf("Enter your grade: "); scanf("%d",&grade); if (grade>90) printf("Grade: A"); else if (grade>80) printf("Grade: B"); else if (grade>70) printf("Grade: C"); else if (grade>60) printf("Grade: D"); else if (grade>50) printf("Grade: E"); else printf("Grade: F"); getch();