Page 136 - TP_Plus_v2.2_Class_8
P. 136

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
                  or false. The program  executes  the  statements                if        False
                  written after ‘if’ block when the condition is true. If     condition
                  it is false, the statements written after ‘else’ block
                  will be executed.                                          True
                                                                        Statement inside if block   Statement inside else
                  However, there might be situations when we need            will execute           block will execute
                  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.
                      AND: Results in true only if both the conditions are true. If any one condition is false, the result will be
                     false.




                  134   Plus (Ver. 2.2)-VIII
   131   132   133   134   135   136   137   138   139   140   141