File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

do and while

Takumi Fujiwara

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

Joined: Jul 08, 2003
Posts: 24199

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

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
I agree. Here's the link:
subject: do and while
It's not a secret anymore!