• Post Reply Bookmark Topic Watch Topic
  • New Topic

does the method always return false?  RSS feed

 
Anissa Pary
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
stupid question but can anyone help. the method:

So my question: for example if "if" statement is true the output of this method would still be false? Or am I wrong? and if I am correct why do we need this "if" statement if whenever "if" true the output still be false???
 
Paul Clapham
Sheriff
Posts: 22816
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anissa Pary wrote:So my question: for example if "if" statement is true the output of this method would still be false?


Let's try to be a little more precise (because the way you have put it is a recipe for maximum confusion). Your code is:


So if the expression

evaluates to true, then the three statements inside the if-block will be executed. (Unless an exception is thrown by one of them.) One of those three statements is "return true", which does indeed return true. And "return" means that nothing else in the method will be executed (except code in a finally-clause, which you don't have).

Does that clarify your question?
 
Anissa Pary
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Anissa Pary wrote:So my question: for example if "if" statement is true the output of this method would still be false?


Let's try to be a little more precise (because the way you have put it is a recipe for maximum confusion). Your code is:


So if the expression

evaluates to true, then the three statements inside the if-block will be executed. (Unless an exception is thrown by one of them.) One of those three statements is "return true", which does indeed return true. And "return" means that nothing else in the method will be executed (except code in a finally-clause, which you don't have).

Does that clarify your question?

Thanks for answering. So you want to say that if "if" is true then it would do only those 3 commands and would be stopped by"return true" statement and it would not execute "return false" statement. If it so then it makes sense. Thank you
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!