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 Needing help with a Do While loop. Getting an Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Needing help with a Do While loop. Getting an "illegal start of expression" error." Watch "Needing help with a Do While loop. Getting an "illegal start of expression" error." New topic
Author

Needing help with a Do While loop. Getting an "illegal start of expression" error.

Michael Rippee
Greenhorn

Joined: Jun 30, 2011
Posts: 19
I'll throw an arrow pointing to the line getting the error. Information is always more appreciated that just a fix, although any help is deeply appreciated! (It's almost all the way to the bottom.)

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Michael Rippee wrote:

Well, that's not a valid expression. What are you trying to achieve there?

(You really shouldn't be using == or != for comparing strings: you should be using the equals() method. But that's not what's stopping it from compiling).
Michael Rippee
Greenhorn

Joined: Jun 30, 2011
Posts: 19
I'm trying to get the program to run from the beginning again when the user inputs Yes at the end.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Well, to just loop round if you enter "Yes":

If you want to wait until they've entered either "Yes" or "No", then you're going to need read from the scanner in a second loop inside the main one.
Michael Rippee
Greenhorn

Joined: Jun 30, 2011
Posts: 19
* feels stupid * OK. Is there a way, for future knowledge to do a "not equal" for a string?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

Michael Rippee wrote:* feels stupid * OK. Is there a way, for future knowledge to do a "not equal" for a string?


Something like ....



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Michael Rippee
Greenhorn

Joined: Jun 30, 2011
Posts: 19
Awesome, thank you. I'll code that in real quick and mark this post resolved if it solves the problem. Of course, I'm still curious why it wouldn't even compile. What I wrote seems like it would be an expression, even if it wouldn't 'work'.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

Michael Rippee wrote:Awesome, thank you. I'll code that in real quick and mark this post resolved if it solves the problem. Of course, I'm still curious why it wouldn't even compile. What I wrote seems like it would be an expression, even if it wouldn't 'work'.


What you wrote ...



is not valid Java. And hence, doesn't compile. Java follows very specific rules that is specified by the JLS -- it is probably better to learn those rules, than to determine it via "seems like" it should work.

Henry
Jay Simon
Greenhorn

Joined: Jul 05, 2011
Posts: 6

Why not simply write

while (reply.equals("Yes")).

This is logically equivalent to what you seem to be getting at. That is, if reply doesn't equal "Yes", code is not going to loop, period. What you wrote is invalid syntax if you meant to stipulate two (unnecessary) conditions for "reply". As was previously suggested, use "equals" for string comparison. With objects in general, "==" only checks for same reference (memory address)..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Needing help with a Do While loop. Getting an "illegal start of expression" error.
 
Similar Threads
Problem with Incompatible Types. Help appreciated, information much more so.
Need help at converting java program to pseudo code
Can someone please help me out.
coin flip assignment help
no main method found