Page 63 - CloudGPT_C8_Flipbook
P. 63

At a Glance
                       Logical operators are the fundamental blocks which adds a decision-making capability to
                       code.

                       AND operator is used to check if two or more conditions are true.
                       OR operator is used to check if either one of two or more conditions is TRUE.
                       NOT operator is used to reverse or negate a condition.

                       To create a complex expression, you may need to combine different logical operators.
                       Relational operator checks the value of the two operands.

                       You may come across complex scenarios in using a single if-else loop might not be enough,
                       in that case you need to use nested conditional statement.
                       If there is another if-else construct within the if block or the else block, this is called nesting.






                      Exercise

                 A.  Tick ( ) the correct option.

                     1.  Observe the pseudocode given below and answer the following questions:
                         Program Start

                         IF (Day is Saturday or Sunday)

                             IF (Time is between 6 PM and 8 PM)
                         THEN

                             Display Play time

                             ELSE
                             Display Study time

                         Program End
                         I.   Today is Monday and the time is 11.30 AM. Is it a study time?

                             a.  True                                  b.  False
                         II.  Today is Saturday and the time is 1.30 AM. Is it a play time?

                             a.  True                                  b.  False

                         III.  Today is Wednesday and the time is 5.30 AM. Is it a study time?
                             a.  True                                  b.  False

                         IV.  Today is Sunday and the time being 09.30 PM. Is it a play time?
                             a.  True                                  b.  False



                                                                                     Control with Conditionals   61
   58   59   60   61   62   63   64   65   66   67   68