src/main/java/io/reactivex/internal/util/AppendOnlyLinkedArrayList.java
@SuppressWarnings("unchecked")
    public <S> void forEachWhile(S state, BiPredicate<? super S, ? super T> consumer) throws Exception {
        Object[] a = head;
        final int c = capacity;
        for (;;) {
            for (int i = 0; i < c; i++) {
                Object o = a[i];
                if (o == null) {
                    return;
                }
                if (consumer.test(state, (T)o)) {
                    return;
                }
            }
            a = (Object[])a[c];
        }
    }
@SuppressWarnings("unchecked")
    public <S> void forEachWhile(S state, BiPredicate<? super S, ? super T> consumer) throws Exception {
        Object[] a = head;
        final int c = capacity;
        for (;;) {
            for (int i = 0; i < c; i++) {
                Object o = a[i];
                if (o == null) {
                    return;
                }
                if (consumer.test(state, (T)o)) {
                    return;
                }
            }
            a = (Object[])a[c];
        }
    }
Loops over all elements of the array until a null element is encountered or
the given predicate returns true.
@param <S> the extra state type
@param state the extra state passed into the consumer
@param consumer the consumer of values that returns true if the forEach should terminate
@throws Exception if the predicate throws