Wednesday June 19, 2019

      SteelArrow Basics
      SteelArrow Tags
  SteelArrow Functions
  SteelArrow Objects
  Advanced Topics
  WAS Overview
  Code Samples
  Site Search

Get SteelArrow!     
  Controlling Script Flow    
Return to Basics Page
Controlling the flow of a script is of uptmost importance. This can easily be considered the most important aspect of any programming language. The ability to make decisions about what code should be executed based on a condition makes it possible to create one script that can perform several useful operations, making code more modular, and easier maintained.

The SteelArrow examples that are used for XML output are great examples of how program flow can be controlled within one script. The scripts .xmlByCol and .xmlByRow first check to see if the parameter output has been defined. If it has not, the page is displayed in HTML, offering a link that does define the output variable.

With the SteelArrow <SAIF> tag, similar processing can be accomplished for any operation. The <SAIF> tag takes an attribute that describes the expression that is to be evaluated. This expression will evaluate to TRUE or FALSE, and will be the sole reason that a block of code is executed.

The general format of the <SAIF> tag is as follows:

<SAIF COND=someVar .eq. "Test">
   <!--- Block to execute if the COND
         attribute evaluates to TRUE --->
<SAELSEIF COND=someVar .eq. "Test1">
   <!--- Block to execute if the COND 
         attribute evaluates to TRUE --->
<SAELSEIF COND=someVar .eq. "Test2">
   <!--- Block to execute if the COND
         attribute evaluates to TRUE --->
   <!--- Block to execute if none of the
         above expressions evaluate to TRUE --->

Another conditional construct available in SteelArrow is the <SASWITCH> statement. This conditional statement is similar to the above <SAIF> tag in that it offers a developer the opportunity to "switch" script behaviour based on the value of an expression.

The above <SAIF> block could be rewritten with <SASWITCH> as follows:

   <SACASE VALUE="Test">
      <!--- Block to execute  --->
   <SACASE VALUE="Test1">
      <!--- Block to execute  --->
   <SACASE VALUE="Test2">
      <!--- Block to execute  --->
      <!--- Block to execute if none 
          of the previous VALUES match --->

<SASWITCH> blocks make code more readable, and remove the necessity to validate an expression at each step of the way. As a worst case scenario, the <SAIF> statement requires the WAS engine to process the expression contained within each <SAIF> and <SAELSEIF> statement before finally dropping into the <SAELSE> block.

With the <SASWITCH> block, the expression is evaluated and the correct <SACASE> block is selected based on its value. This creates code that is more efficient, easier to read and easier to update.


Copyright © 1998-2004 Tomahawk Technologies Inc.
Privacy Policy