control flow once
Documentation for control flow once, assembled from the following types:
From Control Flow
A block prefix with
once will be executed exactly once, even if placed inside a loop or a recursive routine.
my = 3;loop# OUTPUT: «once␤manymanymany»
This works per "clone" of the containing code object, so:
( xx 3).map: ; # says 42 thrice
Note that this is not a thread-safe construct when the same clone of the same block is run by multiple threads. Also remember that methods only have one clone per class, not per object.