[Newbies] Re: go to the end of a loop
joseph.alotta at gmail.com
Tue Apr 26 15:54:26 UTC 2016
thank you. i will studying this.
> On Apr 26, 2016, at 7:48 AM, Balázs Kósi [via Smalltalk] <ml-node+s1294792n4892242h51 at n4.nabble.com> wrote:
> categoriesByPayees := Dictionary new.
> FileStream readOnlyFileNamed: 'payees-by-categories.txt' do: [ :file |
> " With #readOnlyFileNamed:do: you don't have to worry about closing the file,
> it ensures that #close is sent to the file, even if you leave the block through an Exception. "
> [ file atEnd ] whileFalse: [
> | parts |
> parts := (file nextLine findTokens: $| escapedBy: Character tab)
> collect: #withBlanksCondensed.
> " We collect the parts #withBlanksCondensed, so we don't have to call it repeatedly in the loop.
> You can use unary selectors in place of blocks with one argument. You may look at the implementation
> of Collection >> #collect: and Symbol >> #value: to find out why. I'm not sure what you really want is
> #findTokens:escapedBy:, it cuts the string along | characters if they are not preceded by a tab."
> parts size > 1 ifTrue: [
> " We skip blank lines or categories without at least one payee. "
> | category |
> category := parts first.
> parts allButFirstDo: [ :payee |
> at: payee
> ifAbsentPut: [ OrderedCollection new ]) add: category
> " Your implementation only remembers the last category encountered for a payee.
> We can collect all the categories. " ] ] ] ]
View this message in context: http://forum.world.st/go-to-the-end-of-a-loop-tp4891930p4892297.html
Sent from the Squeak - Beginners mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners