This site requires JavaScript, please enable it in your browser!
Greenfoot back
Nosson1459
Nosson1459 wrote ...

2016/10/16

return

Nosson1459 Nosson1459

2016/10/16

#
how do u make a return statement in a boolean method im not really sure how 2 do it
Super_Hippo Super_Hippo

2016/10/16

#
You can use 'return true;' and 'return false;'.
Nosson1459 Nosson1459

2016/10/16

#
and before dat if i want 2 return true if a boolean variable is true i shud write
hit=true;
where hit is my boolean variable or shud i write
hit==true;
Super_Hippo Super_Hippo

2016/10/16

#
The '==' is only used as a condition (like in if-conditions), so it is probably the first one. Show the method.
Nosson1459 Nosson1459

2016/10/16

#
its fine i did trial and error and da 1st one worked thnx
danpost danpost

2016/10/16

#
You may just need to code it this way:
 return hit;
which is more equivalent to your second way:
return hit == true;
danpost danpost

2016/10/16

#
Nosson1459 wrote...
its fine i did trial and error and da 1st one worked thnx
If you are using:
return hit = true;
then the method will only return a true value (because you are assigning 'true' to the 'hit' variable instead of comparing the two -- which '==' would do).
You need to login to post a reply.