Algorithm to do foreach_X_if_C(X)_then_f(X)_else_g(X)