In both cases, if the input list is empty, the result is the value of the accumulator, z.

If not, foldl takes the head of the list, x, and returns the result of recursing on the tail of the list using (f z x) as the new z. foldr returns (f x q) where q is the result of recursing on the tail.