Page 91 - Plus V4 with Adobe class 8
P. 91

Take Off                                                          Century   #Critical Thinking
                                                                                               21 st
                                                                                              Skills
                 Write the output of the following statements:

                  1.  if (today is Sunday)                         2.  if (a>90)
                    then                                             then
                        display “Weekend”                               display “Excellent”
                    else                                             else

                        display “No weekend”                             display “Try harder”
                                                                      Assume the value of a is 85








            We learnt about writing algorithms for a program and using conditional statements in a program. Let
            us learn multiple conditions and looping in a program.


                 MULTIPLE CONDITIONS IN A PROGRAM

            Conditional statements are used in
            a program to instruct the computer                   Yes                           No
                                                                             If (Condition)
            to make a decision. The result of the                            to be checked
            computer’s decision for a condition                 Then                           Else
            will  always  be  either  a  true  or  a   Statements to                                Statements to
            false. The program executes the           be executed                                    be executed
            statements written after ‘if’ when the condition is true. If it is false, the statements written after ‘else’
            will be executed.

            But there might be situations when we need to check for multiple conditions in a program. For example,
            look at these programs:

                                If (3>2) AND (3>4)                    If (3>2) OR (3>4)
                                Then                                  Then
                                   Write “Yes”                           Write “Yes”
                                Else                                  Else
                                   Write “No”                            Write “No”

                                            No                                   Yes


            What did you notice?

            Both the programs have two IF conditions joined together either through AND or OR. And the final
            result depends on the combined result.
                 AND: results in YES only if both the conditions are true. If any condition is false, the result will be false.

                 OR: results in YES if any one of the conditions is true. If both are false, the result will be false.



                                                                                        #Algorithmic Intelligence  89
   86   87   88   89   90   91   92   93   94   95   96