Course of Raku / Essentials / Variables and data types essentials / Boolean type / Exercises / Double negation
Solution: Double negation
Let us extend the program to solve the second part of the exercise and reuse the same variable:
Code
my $value = False;
say !!$value;
$value = True;
say !!$value;🦋 You can find the full code in the file double-negation.raku.
Comments
Before running the program, let us think what it will print. There
are two negation operators before the variable. They act as two negation
operators. In the first case, the value is flipped from
False to True, and then immediately flipped
back from True to False. In the second case,
the algorithm is the same: after two negations, we get the initial
Boolean value.
Output
The program prints the following output, which confirms the above considerations:
$ raku exercises/booleans/double-negation.raku
False
TrueCourse navigation
← Double negation | Triple negation →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська