File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

do and while

 
Takumi Fujiwara
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Where I'm getting the compile time error, the compiler states that ';' is expected. I'm guessing there is something wrong with either my do loop or my while loop, but I can't figure this out.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main problem is exactly what the compiler says: you need a ";" after the while condition -- i.e.,



Now, the other problem is that only the zero-th element of fileStrings is ever set, because every time through the loop, you create a brand-new variable named "i". The declaration of "i" should be moved outside the loop -- i.e., before the "do".
 
Takumi Fujiwara
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I knew something didn't look right. Thanks.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also follow what happens when the read gives a null line back at end of file. The next few lines execute and treat the null like a valid line. A more common way to see this is:

See how putting the test first changes things?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic