[Newbies] Re: next or break in a loop

Bert Freudenberg bert at freudenbergs.de
Mon May 9 21:28:37 UTC 2016


> On 09.05.2016, at 23:00, Joseph Alotta <joseph.alotta at gmail.com> wrote:
> 
> I don’t think any of the solutions work for my case.
> 
> I want to evaluate several different variable for each step, make calculations and if all of the conditions are met, then skip to the next item, otherwise, do the next step of calculations.
> 
> The project is reading comma deliminated bank or credit card files, taking a column of data, counting various characters, and trying to determine what kind of data it is.  For example, a column of data with two slash characters and eight digits per line is likely to be a date field.  A column of data with more than 3 letter characters and a percentage of digits and a percentage of hash signs is likely to be a payee field.  A column of data with no spaces, no digits, no special characters is likely to be a type of transaction field.  A column of data with one period per item, and only digits or a minus sign is  likely to be a amount field, and a column of data with a high percentage of zero length items and the rest having C or K and a pound sign and four or more digits is likely to be a check number field.
> 
> I am doing a lot of tests for each field and I don’t think the switch is a good fit. 

Sounds like my first suggestion would work then. Create a method “processColumn:” that tries to match each pattern and, if successful, reads the data and returns.

This should work, but you would have to put a lot of code into one single method, which is bad style. Better to have a set of parsing methods (e.g. parseAsDate:, parseAsPayee: etc) that would return true if they succeeded, and if not, the next one would be tried.

And instead of having a couple of methods you could have a couple of parser classes that each would try to parse the item. You would put the parsers in a collection and try each of them until one successfully parsed. This would probably be the most object-oriented solution.

- Bert -



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4207 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160509/bd8ff317/smime.bin


More information about the Beginners mailing list