Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: return;

  1. #1
    Member
    Join Date
    Sep 2011
    Posts
    63
    My Mood
    Confused
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default return;

    I'm really sorry, this question is really basic and I expect its already been answered but when I try searching for anything to do with 'return;' I invariably get thousands of results.

    Obviousley when you return 'something' in a statement it returnes that 'something'. But I have a statement in my text book as follows:

    public void run() {
       while (true) {
          if (socket == null) {
          return;
          }
       }
     
    ...
    }
     
    }

    What is being returned?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: return;

    In your use of return there is no value being returned. The return statement exits from the method and "returns" to the caller.

  3. #3
    Member
    Join Date
    Sep 2011
    Posts
    63
    My Mood
    Confused
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: return;

    Thanks Norm, So it is effectively being used as an 'escape'.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: return;

    Where did you get the word "escape" from? What does it mean in this context?
    For me, the return statement returns the execution flow to the caller.

Similar Threads

  1. Return Object does not return the expected output
    By Nour Damer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 13th, 2011, 07:24 AM
  2. Method return value(s)
    By mwr76 in forum Loops & Control Statements
    Replies: 3
    Last Post: October 2nd, 2011, 02:38 PM
  3. Trying to return more than one value as object
    By mwr76 in forum Object Oriented Programming
    Replies: 3
    Last Post: September 30th, 2011, 02:09 PM
  4. [SOLVED] Return statement.
    By Melawe in forum Java Theory & Questions
    Replies: 18
    Last Post: June 20th, 2011, 11:54 AM
  5. how to return value ..
    By gr8mind in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 11th, 2011, 05:27 AM