code: def next_moment_operating_on(self,
                                   qubits: Iterable[ops.Qid],
                                   start_moment_index: int = 0,
                                   max_distance: int = None) -> Optional[int]:
          
          max_circuit_distance = len(self._moments) - start_moment_index
          if max_distance is None:
              max_distance = max_circuit_distance
          elif max_distance < 0:
              raise ValueError('Negative max_distance: {}'.format(max_distance))
          else:
              max_distance = min(max_distance, max_circuit_distance)
  
          return self._first_moment_operating_on(
              qubits,
              range(start_moment_index, start_moment_index + max_distance))
docs: Finds the index of the next moment that touches the given qubits.
  
          Args:
              qubits: We're looking for operations affecting any of these qubits.
              start_moment_index: The starting point of the search.
              max_distance: The number of moments (starting from the start index
                  and moving forward) to check. Defaults to no limit.
  
          Returns:
              None if there is no matching moment, otherwise the index of the
              earliest matching moment.
  
          Raises:
            ValueError: negative max_distance.