Course of Raku / Advanced / Control flow / Block-related phasers / Exercises / Enter a block
Solution: Enter a block
Here is a possible solution to the task.
Code
for 1..2 {
ENTER say '--entering';
say "body $_";
}🦋 You can find the source code in the file enter-a-block.raku.
Output
--entering
body 1
--entering
body 2Comments
ENTERruns each time the block is entered, just before its body. Since the loop enters its body once per iteration,--enteringis printed before eachbodyline.This is the difference between
ENTERandFIRST:FIRSTwould run only once for the whole loop, whereasENTERruns on every entry.
Course navigation
← Enter a block | After each step →