• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to understand how the return keyword is being used in this code  RSS feed

 
Mark Richardson
Ranch Hand
Posts: 108
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am familiar with the return keyword being used in the following contexts:

1. Computing x plus y and giving the result. makes sense.


2. To explicitly make the code return to the calling method (Although, I'm still not clear why this is ever needed because once a method ends, it returns to the calling method anyways...)

4. However, the following code does not make sense to me:




I'm assuming that it is saying "Give me the usedCargoSpace value added to the size value..." but the "<= maxCargoSpace" confuses me...
 
Norm Radder
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the "<= maxCargoSpace" confuses me...

<= is a boolean operator used to compare two expressions for less than or equal.  It returns a boolean value of true or false.  The method it is in is defined to return a boolean value.
 
Mark Richardson
Ranch Hand
Posts: 108
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
the "<= maxCargoSpace" confuses me...

<= is a boolean operator used to compare two expressions for less than or equal.  It returns a boolean value of true or false.  The method it is in is defined to return a boolean value.


So in plain English, it is saying that if used cargo space + the passed size are less than or equal to the max cargo space, return true! Correct?
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that sounds right.
 
Rajith Pemabandu
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose you are correct. The method returns either or evaluating the expression.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!