Hi Joe,

Better than checking for #nextLine answering nil, I think you can send the file 
stream #atEnd
to see if there is any more data.  You would then use a #whileFalse: and move 
the #nextLine
call into the second block of the whileFalse:.  Then test for empty lines with 
something like:
(line size < 2) ifFalse: [...putting all the code that does the work on a line 
with data in
here...].

Lou

PS.   If this is not a school project, we can be of more help, we just don't 
like doing
students projects for them as they learn more with just a few hints and not 
real code.

On Mon, 25 Apr 2016 10:16:33 -0500, Joseph Alotta <[email protected]> 
wrote:

>Greetings,
>
>I have this code:
>
>******
>
>read
>       "read the category file into the dictionary
>       the first item is the category, the rest of the line are payees
>       
>       office expense|home depot|staples|costco
>       groceries|natures best|jewel|trader joes|fresh thyme
>       "
>
>| f line |
>f := FileStream oldFileNamed: myfile.
>
>[(line := f nextLine) notNil] whileTrue: [        | array cat payees |
>               
>                          array := line  findTokens: $| escapedBy:  Character 
> tab .
>
>                                       cat := array first.
>                                       payees := array reject: [ :i | i = cat 
> ].   "rest of the line"
>                                       
>                                       payees do:  [ :p |   mydict at: (p 
> withBlanksCondensed) put: (cat withBlanksCondensed)].
>                          ].
>
>
>f close.
>
>*********
>
>I am getting some blank lines in the data file.  Lines with just a Character 
>cr.  I was wondering how to handle that.  In other languages, there is a break 
>for the loop, to go to the end.  I can do:
>
>(line size < 2) ifTrue: [ f nextLine.].
>
>But that would interfere with the notNil idiom at the end of the file.  So 
>where do I put this.  Is there a common way to jump to the end?
>
>
>Sincerely,
>
>
>Joe.
-- 
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon

_______________________________________________
Beginners mailing list
[email protected]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to