Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dumb question about 'return;'

 
Ryan Jaw
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Sorry in advance for such a dumb question ...
I have the condition where I check to see if my HttpURLConnection response code is okay:
if (code != HttpURLConnection.HTTP_OK)
{
String message = httpConnection.getResponseMessage();
System.out.println(code + " " + message);
return;
}
Suppose that my condition here is met, and the code + message is printed. I'm confused about what 'return;' does. I know this must sound stupid, but I have no idea what purpose it serves
Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are no stupid questions; only people who aren't smart enough to ask!
"return" immediately exits the function it appears in, and returns to the calling function. If you have a return in main(), that ends the program. Elsewhere, it just ends the executing function.
So it just means "we're done here, let's go!"
 
Ryan Jaw
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see. I did not know that. Thanks a bunch!
PS- see if you can find any query that will return an explanation of this from google ... I pulled my hair out
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

PS- see if you can find any query that will return an explanation of this from google ... I pulled my hair out

I agree that Googling for syntactic features of a programing language can be tough -- that's why having paper books, and reading them, is useful. But still, when I searched for "Java return statement" this was the first link, and it does a decent job of explaining "return".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic