Join 244,293 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 935 people online right now. Registration is fast and FREE... Join Now!
if(answere.equalsIgnoreCase("Y")) continue; else if (answer.equalsIgnoreCase("N")) break; } }
Problems with the earlier code was
i) the RETURN statement that will cause the program to return from that function to calling function
ii) the same as with the second RETURN statement also.
iii) I think you want to continue when the input is "Y" and exit the loop while the input is "N".
iv) So, I have replaced those two statements with CONTINUE and BREAK statements respectively.
It is a book example and we want the statement to exit on a Y or N but keep asking if something else is input. I am just confused on why the return true when someone answers Y will not keep the loop running.
Let's explain it simpler: the return instruction ends the current method, no matter if you are 1000 loops deep! Return is the magic keyword to end the method, that's it.
Let's explain it simpler: the return instruction ends the current method, no matter if you are 1000 loops deep! Return is the magic keyword to end the method, that's it.
Ok I think I understand. So return acts like break then.
Let's explain it simpler: the return instruction ends the current method, no matter if you are 1000 loops deep! Return is the magic keyword to end the method, that's it.
Ok I think I understand. So return acts like break then.
Not exactly.
"Break" exits the current loop and continues the code after it. It works with while, do and for loops. Also used to exit a switch case.
Let's explain it simpler: the return instruction ends the current method, no matter if you are 1000 loops deep! Return is the magic keyword to end the method, that's it.
Ok I think I understand. So return acts like break then.
Not exactly.
"Break" exits the current loop and continues the code after it. It works with while, do and for loops. Also used to exit a switch case.
Let's explain it simpler: the return instruction ends the current method, no matter if you are 1000 loops deep! Return is the magic keyword to end the method, that's it.
Ok I think I understand. So return acts like break then.
Not exactly.
"Break" exits the current loop and continues the code after it. It works with while, do and for loops. Also used to exit a switch case.
Post the full code, I'll tell ya. Many objects have the next() function, and they all return different values. Example, the java.sql.ResultSet class has it, and it returns a boolean that tells if another result is available. Post the full code, and I will tell you
This post has been edited by alpha02: 26 Aug, 2007 - 05:45 PM
Post the full code, I'll tell ya. Many objects have the next() function, and they all return different values. Example, the java.sql.ResultSet class has it, and it returns a boolean that tells if another result is available. Post the full code, and I will tell you
no no I was just wondering from the code at the top because I wasn't sure what it stood for. Thats all.
Post the full code, I'll tell ya. Many objects have the next() function, and they all return different values. Example, the java.sql.ResultSet class has it, and it returns a boolean that tells if another result is available. Post the full code, and I will tell you
no no I was just wondering from the code at the top because I wasn't sure what it stood for. Thats all.