SlideShare a Scribd company logo
Conditional Statement
         Presented by:
  Maximino E. Santos Jr.
        Computer Teacher
Conditional Statement


 Conditional statement are statements that check
 an expression then may or may not execute a
 statement or group of statements depending on
 the result of the condition.
The IF statement
 The general form of the if statement is:
      if (expression)
            statement;
 where:
 if is a reserve word in Turbo C
 expression is relational or boolean expression that evaluates
 to a TRUE (1) or FALSE (0) value
 statement may either be a single Turbo C statement or a
 block of Turbo C statements.
The IF statement
 The general form of the if statement with block
 of statements is:
       if (expression)
       {
             statement_sequence;
       }
 In an if statement, if the expression evaluates to TRUE(1),
 the statement or the block statements that forms the target of
 the if statement will be executed. Otherwise, the program
 will ignore the statement or the block of statements.
The IF statement

 Note:

 Never place a semicolon after the expression in
 an if statement.
Example 1
 Write a program that will output
 “Congratulations you PASSED!” if the student’s
 grade is greater than or equal to 60.
Example 2
 Write a program that will ask for a price. If the
 price is greater than 1000, compute a 10%
 discount from the original price. Display the
 computed discount.
The IF-ELSE statement
 The general form of the if-else statement is:
      if (expression)
            statement_1;
      else
            statement_2;
The IF-ELSE statement

 where:
 if is a reserve word in Turbo C
 expression is relational or boolean expression
 that evaluates to a TRUE (1) or FALSE (0)
 value
 statement_1 and statement_2 may either be a
 single Turbo C statement or a block of Turbo C
 statements.
The IF-ELSE statement
 The general form of the if-else statement with
 block of statements is:
      if (expression)
      {
              statement_sequence;
      }
      else
      {
              statement_sequence;
      }
The IF-ELSE statement
 If an if-else statement, if the expression is
 TRUE (1), the statement or block of statements
 after the if statement will be executed;
 otherwise, the statement or block of statements
 in the else statement will be executed.
The IF-ELSE statement

 Note:

 Only the code associated with the if or the code
 that is associated with the else executes, never
 both.
Example 3
 Write a program that will output
 “Congratulations you PASSED!” if the student’s
 grade is greater than or equal to 60. Otherwise
 output, “Sorry you FAILED!”
Fin

More Related Content

What's hot

While loop
While loopWhile loop
While loop
Feras_83
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
Rabin BK
 
Operators in java
Operators in javaOperators in java
Operators in java
Then Murugeshwari
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
Kuppusamy P
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
rajshreemuthiah
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
sharqiyem
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
ASHABOOPATHY
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
Bishal Sharma
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
Pseudocode
PseudocodePseudocode
Pseudocode
grahamwell
 
The Loops
The LoopsThe Loops
The Loops
Krishma Parekh
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition Presentation
Badrul Alam
 
Sets in discrete mathematics
Sets in discrete mathematicsSets in discrete mathematics
Sets in discrete mathematics
University of Potsdam
 
Abstraction and Encapsulation
Abstraction and EncapsulationAbstraction and Encapsulation
Abstraction and Encapsulation
Cheezy Code
 
If and nested if statements
If and nested if statementsIf and nested if statements
If and nested if statements
Rafael Balderosa
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Control structures i
Control structures i Control structures i
Control structures i
Ahmad Idrees
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 

What's hot (20)

While loop
While loopWhile loop
While loop
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
File in C language
File in C languageFile in C language
File in C language
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
The Loops
The LoopsThe Loops
The Loops
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition Presentation
 
Sets in discrete mathematics
Sets in discrete mathematicsSets in discrete mathematics
Sets in discrete mathematics
 
Abstraction and Encapsulation
Abstraction and EncapsulationAbstraction and Encapsulation
Abstraction and Encapsulation
 
If and nested if statements
If and nested if statementsIf and nested if statements
If and nested if statements
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Control structures i
Control structures i Control structures i
Control structures i
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 

Viewers also liked

Zero, First, Second and Third Conditionals ppt
Zero, First, Second and Third Conditionals pptZero, First, Second and Third Conditionals ppt
Zero, First, Second and Third Conditionals ppt
Grace
 
1.3 time talks with an accentfor 1st semester for KU's BBA
1.3 time talks with an accentfor 1st semester for KU's BBA1.3 time talks with an accentfor 1st semester for KU's BBA
1.3 time talks with an accentfor 1st semester for KU's BBAramshrestha12345
 
3.3 propaganda techniques in today’s advertisingfor 1st semester for KU's BBA
3.3 propaganda techniques in today’s advertisingfor 1st semester for KU's BBA3.3 propaganda techniques in today’s advertisingfor 1st semester for KU's BBA
3.3 propaganda techniques in today’s advertisingfor 1st semester for KU's BBAramshrestha12345
 
Propaganda techniques
Propaganda techniques Propaganda techniques
Propaganda techniques
Melodee Peters
 
Conditionals presentation
Conditionals presentationConditionals presentation
Conditionals presentationdouxsara
 
Conditional Sentences
Conditional SentencesConditional Sentences
Conditional Sentences
IES Rosario de Acuña
 
All types of conditionals and wish
All types of conditionals and wishAll types of conditionals and wish
All types of conditionals and wishRomanychch
 

Viewers also liked (7)

Zero, First, Second and Third Conditionals ppt
Zero, First, Second and Third Conditionals pptZero, First, Second and Third Conditionals ppt
Zero, First, Second and Third Conditionals ppt
 
1.3 time talks with an accentfor 1st semester for KU's BBA
1.3 time talks with an accentfor 1st semester for KU's BBA1.3 time talks with an accentfor 1st semester for KU's BBA
1.3 time talks with an accentfor 1st semester for KU's BBA
 
3.3 propaganda techniques in today’s advertisingfor 1st semester for KU's BBA
3.3 propaganda techniques in today’s advertisingfor 1st semester for KU's BBA3.3 propaganda techniques in today’s advertisingfor 1st semester for KU's BBA
3.3 propaganda techniques in today’s advertisingfor 1st semester for KU's BBA
 
Propaganda techniques
Propaganda techniques Propaganda techniques
Propaganda techniques
 
Conditionals presentation
Conditionals presentationConditionals presentation
Conditionals presentation
 
Conditional Sentences
Conditional SentencesConditional Sentences
Conditional Sentences
 
All types of conditionals and wish
All types of conditionals and wishAll types of conditionals and wish
All types of conditionals and wish
 

Similar to Conditional statement

Decision making and looping - c programming by YEASIN NEWAJ
Decision making and looping -  c programming by YEASIN NEWAJDecision making and looping -  c programming by YEASIN NEWAJ
Decision making and looping - c programming by YEASIN NEWAJ
YeasinNewaj
 
Python decision making part4
Python decision making part4Python decision making part4
Python decision making part4
Vishal Dutt
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Hossain Md Shakhawat
 
Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
MLG College of Learning, Inc
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
MLG College of Learning, Inc
 
Python decision making
Python   decision makingPython   decision making
Python decision making
Learnbay Datascience
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statement
FarshidKhan
 
Oracle pl/sql control statments
Oracle pl/sql control statmentsOracle pl/sql control statments
Oracle pl/sql control statments
Tayba Bashir
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
Deepak Lakhlan
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
RAJ KUMAR
 
Modula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statementsModula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statements
Julian Miglio
 
Creating decision structures of a program
Creating decision structures of a programCreating decision structures of a program
Creating decision structures of a programYsa Castillo
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
TejaswiB4
 
Control satkcher ppt
Control satkcher pptControl satkcher ppt
Control satkcher ppt
6336Zeelvora
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
chintupro9
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
ENGWAU TONNY
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5e
Gina Bullock
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5e
Gina Bullock
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
TANUJ ⠀
 
Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6
Mohd Harris Ahmad Jaal
 

Similar to Conditional statement (20)

Decision making and looping - c programming by YEASIN NEWAJ
Decision making and looping -  c programming by YEASIN NEWAJDecision making and looping -  c programming by YEASIN NEWAJ
Decision making and looping - c programming by YEASIN NEWAJ
 
Python decision making part4
Python decision making part4Python decision making part4
Python decision making part4
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
 
Python decision making
Python   decision makingPython   decision making
Python decision making
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statement
 
Oracle pl/sql control statments
Oracle pl/sql control statmentsOracle pl/sql control statments
Oracle pl/sql control statments
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Modula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statementsModula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statements
 
Creating decision structures of a program
Creating decision structures of a programCreating decision structures of a program
Creating decision structures of a program
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
Control satkcher ppt
Control satkcher pptControl satkcher ppt
Control satkcher ppt
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5e
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5e
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6
 

More from Maxie Santos

Tutorial 9 multimedia web page
Tutorial 9 multimedia web pageTutorial 9 multimedia web page
Tutorial 9 multimedia web pageMaxie Santos
 
Basic internet pnhs inset
Basic internet   pnhs insetBasic internet   pnhs inset
Basic internet pnhs insetMaxie Santos
 

More from Maxie Santos (7)

Computer virus
Computer virusComputer virus
Computer virus
 
Html tutorial 5
Html tutorial 5Html tutorial 5
Html tutorial 5
 
Tut 06 (forms)
Tut 06 (forms)Tut 06 (forms)
Tut 06 (forms)
 
Html tutorial 5
Html tutorial 5Html tutorial 5
Html tutorial 5
 
Html tut 04
Html tut 04Html tut 04
Html tut 04
 
Tutorial 9 multimedia web page
Tutorial 9 multimedia web pageTutorial 9 multimedia web page
Tutorial 9 multimedia web page
 
Basic internet pnhs inset
Basic internet   pnhs insetBasic internet   pnhs inset
Basic internet pnhs inset
 

Conditional statement

  • 1. Conditional Statement Presented by: Maximino E. Santos Jr. Computer Teacher
  • 2. Conditional Statement Conditional statement are statements that check an expression then may or may not execute a statement or group of statements depending on the result of the condition.
  • 3. The IF statement The general form of the if statement is: if (expression) statement; where: if is a reserve word in Turbo C expression is relational or boolean expression that evaluates to a TRUE (1) or FALSE (0) value statement may either be a single Turbo C statement or a block of Turbo C statements.
  • 4. The IF statement The general form of the if statement with block of statements is: if (expression) { statement_sequence; } In an if statement, if the expression evaluates to TRUE(1), the statement or the block statements that forms the target of the if statement will be executed. Otherwise, the program will ignore the statement or the block of statements.
  • 5. The IF statement Note: Never place a semicolon after the expression in an if statement.
  • 6. Example 1 Write a program that will output “Congratulations you PASSED!” if the student’s grade is greater than or equal to 60.
  • 7.
  • 8.
  • 9. Example 2 Write a program that will ask for a price. If the price is greater than 1000, compute a 10% discount from the original price. Display the computed discount.
  • 10.
  • 11.
  • 12. The IF-ELSE statement The general form of the if-else statement is: if (expression) statement_1; else statement_2;
  • 13. The IF-ELSE statement where: if is a reserve word in Turbo C expression is relational or boolean expression that evaluates to a TRUE (1) or FALSE (0) value statement_1 and statement_2 may either be a single Turbo C statement or a block of Turbo C statements.
  • 14. The IF-ELSE statement The general form of the if-else statement with block of statements is: if (expression) { statement_sequence; } else { statement_sequence; }
  • 15. The IF-ELSE statement If an if-else statement, if the expression is TRUE (1), the statement or block of statements after the if statement will be executed; otherwise, the statement or block of statements in the else statement will be executed.
  • 16. The IF-ELSE statement Note: Only the code associated with the if or the code that is associated with the else executes, never both.
  • 17. Example 3 Write a program that will output “Congratulations you PASSED!” if the student’s grade is greater than or equal to 60. Otherwise output, “Sorry you FAILED!”
  • 18.
  • 19.
  • 20. Fin