public String getAnswer() {
String answer = null;
If (something == somethingElse) {
answer = "Yo' Momma";
// what would go here to go straight to the return
}
// other stuff which would lead to a different answer
answer = "Yo' Sister"
return answer;
}
Teaching yourself anything is always the cheapest way, but it definitely takes a lot of time and effort.<br /> <br />Thank you javaranch <a href="http://"http://faq.javaranch.com/view?HowToAskQuestionsOnJavaRanch"" target="_blank">Learn How to Ask Your Question</a> and be nice
Originally posted by Nicholas Carrier:
... Basically, how do I stop a method from finishing and go straight to a return?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
"I'm not back." - Bill Harding, Twister
Teaching yourself anything is always the cheapest way, but it definitely takes a lot of time and effort.<br /> <br />Thank you javaranch <a href="http://"http://faq.javaranch.com/view?HowToAskQuestionsOnJavaRanch"" target="_blank">Learn How to Ask Your Question</a> and be nice
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
Note that you may well encounter some people who feel that a return anywhere other than the end of a method is wrong as it makes code "hard to read". These same people generally say the same thing about break (other than in a switch) and continue. I am tempted to say you should ignore these people. But instead, I recommend you react by making a point of inserting as many returns, breaks, and continues as possible in your code, just to annoy those people. That's what I do, anyway.
Originally posted by Stan James:
The discussion about multiple returns was worth having, so I'm glad you didn't delete the question...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
"I'm not back." - Bill Harding, Twister
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'm not back." - Bill Harding, Twister