Page 60 - Computer Genius Class 07
P. 60

Symbol              Operator                            Description                   Example


                        <      Less than                     a is less than b                              (a < b)

                       >=      Greater than or equal to      a is greater than or equal to b               (a >=b)

                       <=      Less than or equal to         a is less than or equal to b                  (a <=b)





                      ‘=’ is an assignment operator, used to assign a value to a variable.
                      ‘==’ is a relational (comparison) operator, used to compare the value of two variables.




                  Precedence of Operators

                  Logical operators also have precedence which determines how the operations are grouped in the
                  absence of parentheses.
                  Parentheses  are  used to group the operands  with their  correct  operator.  In an expression,  the
                  operator   ith  the  highest  precedence  is  grouped   ith  its  operands  first   then  the  ne t  highest
                  operator will be grouped with its operands, and so on.


                                         A + B > C             B + C > A              C + A > B




                                         A + B > C     and     B + C > A      and     C + A > B

                  When there are many logical operators of the same precedence, then the operator will be examined
                  from left to right.



                                              Higher Precedence         Logical Operator


                                                                               not


                                                                               and



                                              Lower Precedence                  or



                  Let us create a program in makecode to check if a number is even or odd.
                  In this task, you will create a program which checks if the entered number is divisible by 2 or not, if
                  the entered number is divisible by 2, then the message will be displayed as ‘Number is even’, else the
                  message will be displayed as ‘Number is odd’.





                       58    Computer Genius-VII
   55   56   57   58   59   60   61   62   63   64   65