Select objects from one group without objects belonging to other group

For example, I have two object groups: group A and group B.
I want to check conditions on all elements contained in group A without elements contained in group A AND group B.
Is there a way to make this “filter” with conditions? Or should I just make these groups separate and remake the events?

Example of what I mean in pseudo code
while true
if object in group A
if object not in group B
do something

What I got working for now is
while true
if object in group A
do something

I tried some ideas but none seemed to work, so I thought I would ask here before choosing a more time consuming route.

Wouldn’t you be able to just add if object in group b and invert it?

Can you tell me what’s the name of condition for checking if object is in group? You mean something like “inverted pick all group b objects”?