File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes dumb question about 'return;' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "dumb question about Watch "dumb question about New topic
Author

dumb question about 'return;'

Ryan Jaw
Greenhorn

Joined: Nov 04, 2003
Posts: 7
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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!"


[Jess in Action][AskingGoodQuestions]
Ryan Jaw
Greenhorn

Joined: Nov 04, 2003
Posts: 7
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

Joined: Jul 08, 2003
Posts: 24183
    
  34


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".
 
 
subject: dumb question about 'return;'
 
Similar Threads
Disadvantages of in-place instantiation of a instance variable
Overall performance of ArrayList vs. HashSet
Problems with my code, any help?
"Professional JSP Tag Libraries"
If condition question