Course of Raku / Advanced / Operators / Types of Raku operators / Exercises / Count up

Solution: Count up

Here is a possible solution to the task.

Code

my $n = 9;

say $n++;
say $n;

🦋 You can find the source code in the file count-up.raku.

Output

9
10

Comments

  1. ++ is a postfix operator: it comes after its operand. Used as an expression, $n++ yields the old value 9 first — which is what say prints — and only then increments the variable.

  2. The second line shows that $n has indeed become 10. (The prefix form ++$n would instead increment first and return 10.)

Course navigation

Count up   |   Boolean of a value