title: Strange loop when using DigestInputStream in Java
body: <p>The following code supposed to compute the hash for a string in a text file using <code>DigestInputStream</code> class in Java.</p>
  
  <pre><code>import java.io.*;
  import java.security.*;
  
  public class ReturnDigest extends Thread {
  
       private File input;
       private byte[] digest;
  
      public ReturnDigest(File input) {
       this.input = input;
      }
  
          public void run() {
            try {
          FileInputStream in = new FileInputStream(input);
          MessageDigest sha = MessageDigest.getInstance("SHA");
          DigestInputStream din = new DigestInputStream(in, sha);
          int b;
          while ((b = din.read()) != -1) ;
          din.close();
          digest = sha.digest();
        }
            catch (IOException ex) {
          System.err.println(ex);
        }
            catch (NoSuchAlgorithmException ex) {
          System.err.println(ex);
        }
  
      }
  
          public byte[] getDigest() {
        return digest;
      }
  
  }
  </code></pre>
  
  <p>My question is: why there is a semicolon after the <code>while</code> statement? Is this correct? When I remove it, I get error. I have not ever heard that it is possible to put a semicolon after a while statement. Can you clarify the case in this code please.</p>