Category:Smalltalk: Difference between revisions

Content added Content deleted
Line 501: Line 501:


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>findSomeElementWhichMeetsCondition:conditionBlock thenDo:actionBlock ifNone:failBlock
<lang smalltalk>
findSomeElementWhichMeetsCondition:conditionBlock thenDo:actionBlock ifNone:failBlock
dataSet do:[:eachElement |
dataSet do:[:eachElement |
(conditionBlock value:eachElement) ifTrue:[
(conditionBlock value:eachElement) ifTrue:[