This page was last modified 1-Mar-2002.

prev | TOC | next

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.


prev | TOC | next
 Join the JTransit Talk List   |   Email JTransit Support   |   Visit http://jtransit.com/
Copyright ©2002 JTransit, Inc., All Rights Reserved
JTransit, JTransit Compiler, JTransit Runtime, FrontLine and RedLine are Trademarks of JTransit, Inc.
ColdFusion is a trademark of Allaire Corp. Tango is a trademark of Pervasive Software, Inc. WiTango is a trademark of With Enterprise Pty Ltd. Other trademarks are property of the respective trademark owners.