def excludeAllBad(good_i, i, j):
    """Exclude endpoints of BK_i where all pixels are flagged as bad.

    Parameters
    ----------
    good_i: array_like
        1-D array of floats, one for each element along the dispersion
        axis.  The values are 0. or 1., depending on the data quality array
        in the background regions.  If any element in the DQ array in
        column i (in either background region) indicates a bad pixel,
        good_i[i] will be 0 (bad); otherwise, it will be 1 (good).

    i: int
        Lower limit of a slice, i:j excludes the X_OFFSET (as shifted
        depending on the wavecal offset).

    j: int
        Upper limit of a slice.

    Returns
    -------
    tuple of two integers
        New values for i and j, such that good_i[i] and good_i[j-1]
        are both > 0 (if there are any such indices)
    """
    nelem = len(good_i)
    done = False
    ip = i
    while not done:
        if ip >= nelem:
            break
        if good_i[ip] > 0.0:
            done = True
            break
        ip += 1
    if not done:
        ip = i
    done = False
    jp = j - 1
    while not done:
        if jp < ip:
            break
        if good_i[jp] > 0.0:
            done = True
            break
        jp -= 1
    if not done:
        jp = j
    jp += 1
    return ip, jp
