import java.util.*;

public class BinarySearch {
  public static void main(String[] args) {
    int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
    System.out.println(find(arr, 11) + " should be " + 10);
  }

  public static int find(int[] arr, int val) {
    int comps = 0;

    int lo = 0;
    int hi = arr.length - 1;
    for (;;) {
      if (hi == lo) return -1;
      int mid = (lo + hi) / 2;
      int v = arr[mid];
      comps++;
      System.out.println(comps);
      if (val == v) {
        return mid;
      } else if (val > v) {
        lo = mid;
      } else if (val < v) {
        hi = mid;
      }
    }
  }
}

@@ -550,24 +550,28 @@
     lo = mid
+ + 1
 ;%0A      %7D el
@@ -600,24 +600,28 @@
     hi = mid
+ - 1
 ;%0A      %7D%0A  

Fix binary search