File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes do and while Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "do and while" Watch "do and while" New topic
Author

do and while

Takumi Fujiwara
Greenhorn

Joined: Nov 17, 2003
Posts: 6


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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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".


[Jess in Action][AskingGoodQuestions]
Takumi Fujiwara
Greenhorn

Joined: Nov 17, 2003
Posts: 6
I knew something didn't look right. Thanks.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
 
subject: do and while
 
Similar Threads
buffer?
Trouble writing to a text file
Writing to a file in Java..?
Why won't the program run?
unresolved error