Page 86 - TrackpadV5.1_class8
P. 86

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



                            MULTIPLE CONDITIONS IN A PROGRAM


                  Conditional  statements  are used  in a program               Start
                  to instruct the computer to make a decision. The
                  result of the condition will always be either true              if        False
                  or false. The program executes  the  statements             condition
                  written after ‘if’ when the condition is true. If it is

                  false, the statements written after ‘else’ will be         True
                  executed.                                             Statement inside if block   Statement inside else
                                                                             will execute           block will execute
                  But there might be situations when we need to
                  check for multiple conditions in a program. For
                  example, look at these programs:                              Stop

                  username = "Orange"

                  password = "secure123"

                  IF username = "Orange" AND password = "secure123" THEN

                      PRINT "Access granted"
                  ELSE

                      PRINT "Access denied"


                        Access granted


                  user_type = "member"

                  coupon_value = "invalid"

                  IF user_type = "member" OR coupon_value = "valid" THEN

                      PRINT "Eligible for discount"
                  ELSE

                      PRINT "Not eligible for discount"


                      Eligible for discount


                  WHAT DID YOU NOTICE?

                  Both  the programs have two IF  conditions  joined  together  using AND  or OR.  The  final  result
                  depends on the combined result.




                   84   Pro (V5.1)-VIII
   81   82   83   84   85   86   87   88   89   90   91