title: How to return a value inside of while loop
body: <p>I have a method, return type is <code>List&lt;User&gt;</code>. In this method I have infinite while loop to accept information from another client over socket. Once a new client accepts, I will add this user into list and continue to listen for new client. I give the construction of the method. It is suppose to accept multiple client. Right now, only allow me to accept one client. Before, we did not set the type as <code>List&lt;User&gt;</code>, then there is no <code>return UserList</code> and whole code works fine with multiple user. After I add a return type of Method, it doesn't works. </p>
  
  <pre><code>public List&lt;User&gt; accept() {
      List&lt;User&gt; userList = new List&lt;User&gt;();
      while (true) {   
          Command_Listening_Socket = server.Accept();
  
          int msgLenght = Command_Listening_Socket.Receive(msgFromMobile);// receive the byte array from mobile, and store into msgFormMobile
          string msg = System.Text.Encoding.ASCII.GetString(msgFromMobile, 0, msgLenght);// convert into string type
  
          if (msg == "setup") {
              my_user = new User();
              userList.Add(my_user);
          }
          return userList;
      }
  }
  </code></pre>