Reputation: 885
This is a quick question about some code I want to use, but I don't have everything clear.
Does this :
return <SOMETHING> == <SOMETHING ELSE>;
and this :
if (<SOMETHING> == <SOMETHING ELSE>)
return true;
else
return false;
mean the same thing ?
Thanks to all who put their time here. Cheers :)
Upvotes: 0
Views: 79
Reputation: 887285
No.
Your first line will return no matter what.
Your second line will only return if the condition is true; if the condition is false, the function will continue executing.
Your first line is equivalent to
if (<SOMETHING> == <SOMETHING>)
return true;
return false;
(or with else
)
EDIT: Yes; exactly.
Upvotes: 10
Reputation: 27659
return <SOMETHING> == <SOMETHING>;
alternate of above is
if (<SOMETHING> == <SOMETHING>)
return true;
else
return false;
Upvotes: 1
Reputation: 48558
First will return the actual result of evaluation
return <SOMETHING> == <SOMETHING>;
but second can be used to send evaluation or inverse of evaluation.
if (<SOMETHING> == <SOMETHING>)
return true;
or
if (<SOMETHING> == <SOMETHING>)
return false;
Upvotes: 1