On 4. 4. 2019 13:16, Roelof Wobben wrote:
Hello,
For a challenge of Exercism I need to check if some parenthes and brackets are balanced.
so for example
()Â = true ([])Â = true
but (])Â is not true because the bracket has no opening bracket.
Now I wonder if I can premature end a #do:Â like this
collection do: [:element | (condition with element) ifFalse: [^false]]
in pseudo code
is this a valid way to end the do ?
Not sure I understand your question properly, but yes, you can do this, it is called "non-local return" and is a known pattern in Smalltalk.
or is there a better way ?
(collection detect: [:element | (condition with element) not] ifNone: [sentinel]) == sentinel ifFalse: [ ^false ] for example does not force you to employ it, as well as (collection allSatisfy: [:element | (condition with element)]) ifFalse: [ ^false ]
Roelof
Herby