title: Use of infinite loop in AtomicInteger.addAndGet(int)
body: <p>In Java's package java.util.concurrent.atomic AtomicInteger class has a method <a href="http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/java/util/concurrent/atomic/AtomicInteger.java#AtomicInteger.addAndGet%28int%29" rel="nofollow">addAndGet(int)</a></p>
  
  <p>which is</p>
  
  <pre><code>public final int addAndGet(int delta) {
      for (;;) {
          int current = get();
          int next = current + delta;
          if (compareAndSet(current, next))
              return next;
      }
  }
  </code></pre>
  
  <p>Why it uses infinite loop here to set a value?</p>