Exercises - Priority of Operators

About this task

Procedure

  1. What are the answers to the following examples?
    1. 22 + (12 * 1)
    2. -6 / -2 > (45 % 7 / 2) - 1
    3. 10 * 2 - (5 + 1) // 5 * 2 + 15 - 1
  2. In the example of the student and the college from the previous exercise on page Exercises - Using Logical Expressions, if the parentheses were removed from the student's formula, what would be the outcome for the college?
    IF  inexpensive | scholarship & reputable | nearby  THEN
       SAY  "I'll consider it."
    ELSE
       SAY  "Forget it!"

    Remember the college is inexpensive, did not offer a scholarship, is reputable, but is 1000 miles away.

Results

ANSWERS
  1. The results are as follows:
    1. 34 (22 + 12 = 34)
    2. 1 (true) (3 > 3 - 1)
    3. 32 (20 - 2 + 15 - 1)
  2. I'll consider it.
    The & operator has priority, as follows, but the outcome is the same as the previous version with the parentheses.
    IF  inexpensive | scholarship & reputable | nearby  THEN
        \_________/   \_________/   \_______/   \____/
           true          false        true      false
             \             \___________/         /
              \                false            /
               \_________________/             /
                      true                    /
                        \____________________/
                                true

Task Task

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/dfhrx00037.html