# binary search invariant: if target is present, it lies within items[low..high]
 while low <= high:

   mid = (low + high) // 2
   # after this check, the invariant still holds for the half we keep:
   if items[mid] < target: low = mid + 1 # target must be in the right half
   elif items[mid] > target: high = mid - 1 # target must be in the left half
   else: return mid
