Course of Raku / Advanced / Operators / Review of operator behaviour / Exercises / Force the order

Solution: Force the order

Here is a possible solution to the task.

Code

say 2 ** (3 + 1);

🦋 You can find the source code in the file force-the-order.raku.

Output

16

Comments

  1. Without the parentheses, ** would bind tighter than +, giving (2 ** 3) + 1 = 9.

  2. The parentheses raise the precedence of the addition, so 3 + 1 is computed first and the expression becomes 2 ** 4, which is 16. Parentheses always let you override the default precedence.

Course navigation

Force the order   |   Power tower