Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 148 - 2615_KEC
P. 148

    OPERATORS AND CONDITIONAL STATEMENTS

                      In  App  Lab, operators  and  conditional  statements  help  you  perform  calculations,
                      compare values and make decisions in your program.

                      ARITHMETIC OPERATORS

                      Arithmetic operators allow us to perform calculations:

                       Operator       Description                      Example

                       +              Addition                         score + 10
                       -              Subtraction                      lives - 1

                       *              Multiplication                   price * 2

                       /              Division                         total / 4
                       %              Modulus (remainder)              5 % 2

                      Example: To perform arithmetic operations.

                      var num1 = 10;

                      var num2 = 3;

                      var sum = num1 + num2;

                      var difference = num1 - num2;

                      var product = num1 * num2;

                      var quotient = num1 / num2;

                      var remainder = num1 % num2;
                      var outputText = "Addition: " + sum + "\n" + "Subtraction: " +
                      difference + "\n" + "Multiplication: " + product + "\n" + "Division:
                      " + quotient + "\n" + "Remainder: " + remainder;

                      setText("outputArea", outputText);

                      Note: To perform it, add label in design mode.

                      146   Premium Edition-V

| 143 144 145 146 147 148 149 150 151 152 153 |