Page 67 - Digicode_AI_class_8
P. 67

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.      A + B > C              B + C > A              C + A > B
            In  an  expression,  the  operator  with
            the  highest  precedence  is grouped
            with its operands first, then the next     A + B > C      and     B + C > A     and      C + A > B
            highest operator will be grouped with
            its operands, and so on.
            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’.




                                                                           Advanced MakeCode Arcade      65
   62   63   64   65   66   67   68   69   70   71   72