Subject: RE: Executing Multiple Statements in Formula
RE:
. . @if(Condition 1 ; action 1 ;
. . . . @if(Condition 2 ; Action 2 ;
. . . . . . @if(Condition 3: Action 3:
. . . . . . . .“” ) ) )
As more conditions got added, it become a nightmare to maintain. Brian’s example and Stephen’s explanation helped me a great deal.
With Nested IFs you need to be careful, with what you wrote above you don’t really need nested ifs as it says:
if Condition1 then Action1
else if Condition2 then Action2
. . . . else if Condition3 then Action3
. . . . . . . . else nothing
which could have been written in one if statement.
HOWEVER if the code had been like this:
@if(Condition 1 ;
. . @if(Condition 2 ;
. . . . @if(Condition 3: Action 3; “”);
. . . . Action2 );
. . Action1 )
Then that code looks like
if Condition1 then
. . if Condition2 then
. . . . if Condition3 then Action 3
. . . . else Nothing
. . else Action2
else Action1
That’s why you want to spend a bit of time to make sure you have a “style” when coding to help make it readible and help you maintain the code.
I personally use tab to try and line things up so you might use the following formatting:
Simple Case:
@if( Condition1;
TrueCase;
ElseCase
)
getting into nested IFs you get:
@if(Condition1;
@if(ConditionA:
TrueCase for ConditionA;
ElseCase for ConditionA
);
Condition2;
TrueCase for Condition2;
Condition3;
TrueCase for Condition3;
Otherwise
)
I like to use tab as I find spacing may not be prounced enough when dealing with a lot of nested ifs.
Of course the other problems is if you have a lot of nested ifs you may start wrapping around depending upon how complex your conidtions are. This is why I tend to tab in front of my condition so I can line things up if there are
multiple parts to the condition
@if(@Left(@Uppercase(LongVariableName);1) = “Y” &
@Elements(AnotherVariable) > 0 &
@IsMember(“Apples”;Fruit);
TrueCase;
FalseCase
)
Of course this is not a hard and fast rule, if it’s a simple if I often just write it on one line.