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
10Comments
++is a postfix operator: it comes after its operand. Used as an expression,$n++yields the old value9first — which is whatsayprints — and only then increments the variable.The second line shows that
$nhas indeed become10. (The prefix form++$nwould instead increment first and return10.)
Course navigation
← Count up | Boolean of a value →