Category:Smalltalk: Difference between revisions
Content added Content deleted
Line 498: | Line 498: | ||
=== Return from a Block === |
=== Return from a Block === |
||
it should be noted that a "ˆ" (return) inside a block will return from the enclosing method, NOT only from the block |
it should be noted that a "ˆ" (return) inside a block will return from the enclosing method, NOT only from the block. And that this is an essential semantic property of the return (technically, it may be a long return from a deeply nested call hierarchy, possibly involving unwind actions). |
||
This makes it possible to pass a block to eg. collections to enumerate elements up-to and until some condition is met. For example, if we need a helper method, which returns the first element from a dataset which meets some condition, we can write: |
This makes it possible to pass a block to eg. collections to enumerate elements up-to and until some condition is met. For example, if we need a helper method, which returns the first element from a dataset which meets some condition, we can write: |
||
<lang smalltalk> |
<lang smalltalk> |