There is a very powerful community created rules engine, called core, which allows you to have multilevel “if” statements including “if A and B while C but not D.”
You’d need to use custom code, which is pretty straightforward: basically you’re going to copy the author’s code and paste it into your account. Here’s the FAQ for that
Then if you decide that something you’d like to try, there are two forum threads you will need for core.
The first is the author’s thread where you get the actual code.
The second is a peer assistance thread where community members can help you figure out how to set up any particular rule you want. (In core, an individual rule is called a “piston.”)
So Core is very powerful, but also quite complicated.
If by chance you have an iPhone, there is a third-party app, SmartRules, which costs about $10 and is also very popular. It is much simpler than core and cannot do as much, but it does have a “do while” option which many people find very useful. It’s easy to install, you do it like any other app from the App Store.