Course of Raku / Advanced /
Control flow / given and when
/ Matching ranges, types, and
conditions
Quiz — when
What does the following program print?
given 5 {
when $_ > 0 { say 'positive' }
when 5 { say 'five' }
}| 1 | positive |
| 0 | five |
| 0 | both lines |
| 0 | nothing |
A when block automatically breaks out of the
given after it matches — there is no fall-through.
5 satisfies the first condition $_ > 0, so
positive is printed and the second when 5 is
never reached, even though it would also have matched.
Course navigation
← Matching ranges, types, and conditions | Life stage from age →