Page 51 - Touchcode_C6_Flipbook
P. 51

OR Operator
                 The OR operator is used to check if at least one of two or more conditions is TRUE or Yes.

                 In OR operator:

                    If any of the condition is true, the operator returns TRUE or Yes.
                    If all the conditions are false, the operator returns FALSE or No.


                                                                                                       Critical Thinking
                  Example 2: You can play outside for an hour, if you have completed
                  your homework, or the time is past 6 PM. Otherwise, you should not
                  go outside to play.



                 Conditions:  1.  Have you completed your homework?

                               2.  Is the time past 6 PM?
                 Decision: Can you play outside for an hour or not?


                 Answer: If you have completed your homework or the time is past 6 PM, you can go outside
                 to play for an hour.

                 If you have not completed your homework, you should complete it first before going out.

                 Pseudocode:

                      Program Start
                      IF  (You have completed your homework) OR (The time is past 6 PM)
                      THEN

                            Go to play outside for an hour
                      ELSE
                            Complete your homework
                      Program End

                 Possible combinations of the example 2:

                                Condition 1                          Condition 2                   Decision
                       (Have you completed your                   (Is the time past          (Should you go to
                                homework?)                              6 PM?)                      play?)
                                     Yes                                  Yes                         Yes
                                     Yes                                  No                          Yes
                                     No                                   Yes                         Yes
                                     No                                   No                          No
                 NOT Operator

                 NOT operator is used to reverse or negate a condition.

                                                                                     Control with Conditionals   49
   46   47   48   49   50   51   52   53   54   55   56