Using SWITCH Instead of IFEQUAL
Typically in Tango you have blocks of code like the following to test a variable for any one of a number of possible values:
<@IFEQUAL <@VAR local$sectionid> 1000029>
show this
<@ELSEIFEQUAL <@VAR local$sectionid> 1000030>
show this
<@ELSEIFEQUAL <@VAR local$sectionid> 1000031>
show this
<@ELSE>
else show this
</@IF>
That will work fine, of course, but for example if your sectionid is 100031 that means the code has to evaluate the <@VAR local\$sectionid> three times. This isn't costly, but in some situations you might have a more complicated expression that's common in all the comparisons. In such cases you are much better off by using a @SWITCH statement like this:
<@SWITCH EXPRESSION="<@VAR local$sectionid>">
<@CASE VALUE="1000029">
show this
</@CASE>
<@CASE VALUE="1000030">
show this
</@CASE>
<@CASE VALUE="1000031">
show this
</@CASE>
<@DEFAULTCASE>
else show this
</@DEFAULTCASE>
</@SWITCH>
The above looks like more code, but it processes more efficiently because as you can see the <@VAR local$sectionid> only occurs once instead of three times. You can also put ANY mathematical expression in the EXPRESSION attribute of the @SWITCH tag, unlike with @IFEQUAL; this is to encourage processing an expression only once (when the @SWITCH first starts executing) and comparing to static values in each @CASE tag until a match is found. If no match is found, the @DEFAULTCASE block is executed.
|