Rexx 程式設計/Rexx 指南/運算子優先順序
外觀
運算子優先順序規則用於確定在表示式求值過程中運算子的執行順序。一個沒有經驗的程式設計師可能會期望以下程式中的表示式產生 35 的結果。然而,實際上它會產生 23 的值,因為乘法優先順序高於加法,所以它會先執行。
/* 這不會產生 23 的值 */ say 3 + 4 * 5
可以透過使用圓括號來改變表示式中運算子的求值順序。在以下示例中,表示式產生 35 的值,因為圓括號的優先順序高於乘法,所以它們的內容會先求值
/* Parentheses cause the addition to be evaluated before the multiplication */ say (3 + 4) * 5
圓括號內的運算子或函式組具有與正常情況相同的優先順序。在以下示例中,圓括號內的乘法會先於加法執行
/* The multiplication within the parentheses is evaluated before the addition */ say 3 * (4 + 2 * 3)
say 5 - 2 + 1