views:

92

answers:

3

I have loop designed to validate the user input on a question, it was working fine until I added this;

        if (userInput.charAt(0) > NUMCOLS && userInput.charAt(0) < 0);
        {
            System.out.println("Error, " + userInput + " is an invalid move.");
            continue;
        }

before this

        if (userInput.charAt(2) !='-')
        {
            System.out.println("Error, " + userInput + " is an invalid move.");
            continue;
        }

Now whenever I try to compile I get an error stating that this is an unreachable statement, what is causing this?

+9  A: 

There's a spurious ';' in the first line of your added code that makes the first continue; always execute!

Stephen C
+3  A: 

There seems a logical error too, both of those conditions cannot be true at the same time.

Read it out loud :

If the user inputs first character is greater than NUMCOLS and its less than 0! If NUMCOLS is 0 or greater, the second condition cannot be true at the same time, and vice versa.

Amir Afghani
OK - I'm wrong about this being the cause of your compilation error, but your logic does seem wrong. How can both of those conditions be true at the same time?
Amir Afghani
Troy
Amir Afghani
That still doesn't work, I only want it to be true if the value entered is outside the range, hence returning the error.No matter what I enter at the moment I receive a false...
Troy
Ah, so what you want is: userInput.charAt(0) < 0 || userInput.charAt(0) > 8
Amir Afghani
Yes, that fixed it, thankyou!
Troy
You understand why, right? It's important to think this through.
Amir Afghani
+3  A: 

your if test has an empty body!

so the code below is always executed and since there's a continue code the following instructions are never executed..

Jack