Does Smalltalk have a way to break out of a block?
Ned Konz
ned at bike-nomad.com
Wed May 30 02:14:11 UTC 2001
On Tuesday 29 May 2001 15:25, reic0024 at d.umn.edu wrote:
> Hello everyone,
>
> Short question: Does Smalltalk have a way to break out of a block like
> "break" does in C?
yes and no. What (many/most) Smalltalks have is the ability of returning from
the inside of a block:
innerMethod1
true whileTrue: [ done ifTrue: [ ^self ] ]
outerMethod
true whileTrue: [ self innerMethod1. self innerMethod2 ].
So when the done flag is set, innerMethod1 returns and thereby breaks out of
its while loop. Typically code can be re-factored so that this can be done.
In your case, you have a multi-way conditional on string prefixes. This can
be written:
d _ Dictionary new
at: 'ice:' put: [ :s | (s findTokens: 'ice:') first ];
at: ':ELEVATION:' put: [ :s | params at: #elevation put: ((s findTokens:
':ELEVATION:') first)
--
Ned Konz
currently: Stanwood, WA
email: ned at bike-nomad.com
homepage: http://bike-nomad.com
More information about the Squeak-dev
mailing list
|