I have found a statement in a book saying that "In anyone non flow process there will be either heat supplied or hear rejected but not both similarly there will be either work input or work output but not both, Hence $$U_2 -U_1 = Q + W $$
Now what is meant by either one and not both?