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

types of loops and what is loop
types of loops and what is looptypes of loops and what is loop
types of loops and what is loop
waheed dogar
 
Strings
StringsStrings
Strings
Mitali Chugh
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
Mahantesh Devoor
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
Ahmad Idrees
 
C if else
C if elseC if else
C if else
Ritwik Das
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
Vishvesh Jasani
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
University of Potsdam
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
tanmaymodi4
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
Ideal Eyes Business College
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
Neeru Mittal
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
Archana Gopinath
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
Darshan Patel
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
Raj Parekh
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
RaginiJain21
 
Looping statement
Looping statementLooping statement
Looping statement
ilakkiya
 
Control structures in c
Control structures in cControl structures in c
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
Saad Sheikh
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 

What's hot (20)

types of loops and what is loop
types of loops and what is looptypes of loops and what is loop
types of loops and what is loop
 
Strings
StringsStrings
Strings
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
C if else
C if elseC if else
C if else
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
Conditionalstatement
ConditionalstatementConditionalstatement
Conditionalstatement
 
Looping statement
Looping statementLooping statement
Looping statement
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 

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 BBA
ramshrestha12345
 
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
ramshrestha12345
 
Propaganda techniques
Propaganda techniques Propaganda techniques
Propaganda techniques
Melodee Peters
 
Conditionals presentation
Conditionals presentationConditionals presentation
Conditionals presentation
douxsara
 
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 wish
Romanychch
 

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 program
Ysa 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

Computer virus
Computer virusComputer virus
Computer virus
Maxie Santos
 
Html tutorial 5
Html tutorial 5Html tutorial 5
Html tutorial 5
Maxie Santos
 
Tut 06 (forms)
Tut 06 (forms)Tut 06 (forms)
Tut 06 (forms)
Maxie Santos
 
Html tutorial 5
Html tutorial 5Html tutorial 5
Html tutorial 5
Maxie Santos
 
Html tut 04
Html tut 04Html tut 04
Html tut 04
Maxie Santos
 
Tutorial 9 multimedia web page
Tutorial 9 multimedia web pageTutorial 9 multimedia web page
Tutorial 9 multimedia web page
Maxie Santos
 
Basic internet pnhs inset
Basic internet   pnhs insetBasic internet   pnhs inset
Basic internet pnhs inset
Maxie 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