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

Conditional statement

  • 1.
    Conditional Statement Presented by: Maximino E. Santos Jr. Computer Teacher
  • 2.
    Conditional Statement Conditionalstatement 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 Writea program that will output “Congratulations you PASSED!” if the student’s grade is greater than or equal to 60.
  • 9.
    Example 2 Writea 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.
  • 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 Writea program that will output “Congratulations you PASSED!” if the student’s grade is greater than or equal to 60. Otherwise output, “Sorry you FAILED!”
  • 20.