SlideShare uma empresa Scribd logo
1 de 20
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

Mais conteúdo relacionado

Mais procurados

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Ankur Pandey
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 
Command line arguments
Command line argumentsCommand line arguments
Command line argumentsAshok Raj
 
Complete Tokens in c/c++
Complete Tokens in c/c++Complete Tokens in c/c++
Complete Tokens in c/c++Shobi P P
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsEng Teong Cheah
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and FlowchartsDeva Singh
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in JavaJin Castor
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case StatementsDipesh Pandey
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
Control structure C++
Control structure C++Control structure C++
Control structure C++Anil Kumar
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 

Mais procurados (20)

FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++
 
Iteration Statement in C++
Iteration Statement in C++Iteration Statement in C++
Iteration Statement in C++
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Switch case in C++
Switch case in C++Switch case in C++
Switch case in C++
 
Data types
Data typesData types
Data types
 
Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Command line arguments
Command line argumentsCommand line arguments
Command line arguments
 
Complete Tokens in c/c++
Complete Tokens in c/c++Complete Tokens in c/c++
Complete Tokens in c/c++
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Presentation on C Switch Case Statements
Presentation on C Switch Case StatementsPresentation on C Switch Case Statements
Presentation on C Switch Case Statements
 
String functions in C
String functions in CString functions in C
String functions in C
 
Loops c++
Loops c++Loops c++
Loops c++
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 

Destaque

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 pptGrace
 
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
 
All types of conditionals and wish
All types of conditionals and wishAll types of conditionals and wish
All types of conditionals and wishRomanychch
 

Destaque (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
 

Semelhante a 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 NEWAJYeasinNewaj
 
Python decision making part4
Python decision making part4Python decision making part4
Python decision making part4Vishal Dutt
 
Cse lecture-6-c control statement
Cse lecture-6-c control statementCse lecture-6-c control statement
Cse lecture-6-c control statementFarshidKhan
 
Oracle pl/sql control statments
Oracle pl/sql control statmentsOracle pl/sql control statments
Oracle pl/sql control statmentsTayba Bashir
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlanDeepak Lakhlan
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in CRAJ KUMAR
 
Modula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statementsModula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statementsJulian 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 ppt6336Zeelvora
 
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 languagechintupro9
 
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 controlENGWAU TONNY
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eGina Bullock
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eGina Bullock
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 

Semelhante a 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 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
 
Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
 
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
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
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
 

Mais de Maxie Santos

Mais de 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