September 2017
Beginner
402 pages
9h 52m
English
The operator %% is called a divisibility operator. It tells if the left operand can be integer divided by the right operand without a remainder.
For example, the integer division of 10 by 3 gives 1 in the remainder and, thus, the %% operator will return false. If you divide 12 by 3, then there is no remainder, and the result is true, as shown here:
say 10 %% 3; # Falsesay 12 %% 3; # True
The result of $a %% $b is the same as the following comparison:
($a % $b) == 0
It can be used to check the condition in the loop, which we will see loops in more detail in Chapter 5, Control Flow. For example, to print the message once per every 1000 iterations, write the following piece of code:
for (0 .. 100_000) { say $_ if $_ %% ...Read now
Unlock full access