Seek help to convert IIF to IF-Else statement

I have a problem when converting IIF to IF-Else statement due to lacking skill and knowledge.
What I want to do is as below: (Periodicity: Daily)
When signal occur this week, Buy on next Monday.
If next Monday is the end of Month, Buy on the following day (i.e. Tuesday).

I used IIF but failed to achieve that. Below is what I wrote:

// Don't trade on last day of month
LastDayOfMonth = Day() > Ref( Day(), 1 );

// Usually it is Monday
BeginOfWeek = DayOfWeek() < Ref(DayOfWeek(),-1);

// Usually it is Friday
EndOfWeek = DayOfWeek() > Ref(DayOfWeek(),1);

// Signal occur on Friday
BuyOK =  EndOfWeek AND BuySignal;

// Buy on next Monday. Therefore, Buy = Ref(BuyOK, -1).
// But if Monday is also the end of Month... 
LastdayBuyCond = Ref(BuyOK, -1) AND LastDayOfMonth;

// then buy on the following day.
Buy = IIf (LastdayBuyCond, BarsSince(LastDayOfMonth)==1, Ref(BuyCondOK, -1));

Sell = 0;

Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );

Plot( C, "Close", colorPink, styleDots );
PlotShapes( Buy*shapeUpArrow, colorGreen, 0, Low );
PlotShapes( Sell*shapeDownArrow, colorRed, 0, High );
PlotShapes( BeginOfWeek*shapeDigit1, colorGold, 0, Low, -30 );
PlotShapes( EndOfWeek*shapeDigit5, colorBlue, 0, Low, -30 );
PlotShapes( LastDayOfMonth*shapeHollowStar, colorYellow, 0, Low, -50 );

Blue "5" means Friday (End of week).
Yellow "1" means Monday (Begin of week).
Yellow Hollow Star means End of Month.)
Since Signal occurs on Friday (27/9/2013), and next Monday (30/9/2013) is end of month,
Therefore it should Buy on next Tuseday (2/10/2013).

Then I realised that IIF is not flow-control. That may be the reason why I used BARSSINCE but no Buy action was taken on Tuesday.
I tried to use IF-Else statement and Loop but I am very weak in writing it.
Would anyone help to convert it to a proper code?
Your kind help is appreciated.

Actually, IIf() is the correct function for you to use. I suggest you add a bit of code:

Filter = True;
AddColumn(...your variables here...);

so that you can run this AFL as an Exploration. That will help you understand which of your variables do not have the values that you expect on any given day.

Thanks for your reply.
Exploration is a good method.
In order to improve my coding skill, I will keep learning how to achieve my purpose.
Thanks again and Happy Easter.