Course of Raku / Advanced / Control flow / Statement prefixes 🆕 / do and the value of a block

Quiz — do

What does the following program print?

my $s = do given -3 {
    when $_ < 0 { 'neg' }
    default     { 'nonneg' }
};
say $s;
1neg
0nonneg
0-3
0Nil

do works in front of control structures, not only bare blocks. Here do given turns the whole given/when into an expression. The topic -3 matches $_ < 0, so the expression yields 'neg', which is stored in $s.

Course navigation

do and the value of a block   |   Laziness and eagerness