Page 149 - DCAP408_WEB_PROGRAMMING
P. 149

Unit 5: Scripting Language




          5.5 Operators                                                                         Notes


          Assignment Operator

          The most common assignment operator is the equal sign. It sets one item equal to another.

             Operator   What does it do?      Example/Explanation
             =        Sets one value equal to another   counter=0
                                              Sets the counter to equal the number 0
             +=       Shortcut for adding to the   clicks += 2
                      current value.          Sets the variable named counter to equal the current
                                              value plus two.
             -=       Shortcut for subracting from   clicks -= 2
                      the current value.      Sets the variable named counter to equal the current
                                              value minus two.
             *=       Shortcut for multiplying the   clicks *= 2
                      current value.          Sets the variable named counter to equal the current
                                              value multiplied by two.
             /=       Shortcut for dividing the   clicks /= 2
                      current value.          Sets the variable named counter to equal the current
                                              value divided by two.


          Comparison Operator

          The comparison operators compare two items and return a value of “true” if the conditions are
          true.

             Operator   What does it do?           Example/Explanation
             ==      Returns a true value if the items are the   counter==10 >
                     same                          Returns the value "true" if the counter's value
                                                   is currently equal to the number 10
                     Returns a true value if the items   counter!=10
                     arenot the same               Returns the value "true" if the counter's value
                                                   is any value except the number 10
             >       Returns a true value if the item on the   counter>10
                     left is greater than the item on the right   Returns the value "true" if the counter's value
                                                   is larger than the number 10
             >=      Returns a true value if the item on the   counter>=10
                     left is equal to or greater than the item   Returns the value "true" if the counter's value
                     on the right                  is equal to or larger than the number 10
             <       Returns a true value if the item on the   counter<10
                     left is less than the item on the right   Returns the value "true" if the counter's value
                                                   is smaller than the number 10
             <=      Returns a true value if the item on the   counter<=10
                     left is equal to or less than the item on   Returns the value "true" if the counter's value
                     the right                     is equal to or less than the number 10









                                           LOVELY PROFESSIONAL UNIVERSITY                                   143
   144   145   146   147   148   149   150   151   152   153   154