Avoid the NULL (None, nil, whatever) and return an empty array/list/collection/container/object/sequence/set/etc/etc instead. It can pass transparently through the same logic (loop), as though it were populated, but it will effectively break past the loop at its initial conditional test (the while/for condition). This eliminates the necessity for additional code which checks for nulls and it allows the caller to cleanly separate, and focus solely on, their own concerns.