• Post Reply Bookmark Topic Watch Topic
  • New Topic

Confused about for and return  RSS feed

 
Lynne Dixon
Greenhorn
Posts: 9
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused about a piece of code that has 2 returns in it.

The method is essentially this:



So if the conditions of the if are met, does the method return 1 and then stop? Or does it return 1 and then also return 0? Or if the conditions of the if are not met, is that when it returns 0?

Thanks for your help

 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A return causes the method to terminate - it doesn't continue on.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lynne Dixon wrote:
So if the conditions of the if are met, does the method return 1 and then stop?


If the conditions of the if statement are met, it returns 1. And no, it doesn't stop. It simply returns 1 to the caller ... meaning the value of one is returned to the calling code, and it is used by the calling code ... and it then runs whatever it is supposed to run next in the caller's code.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!