Using Control ActionsBranch, If, Loop, Break, and Return ActionsTango application files can contain control actions that control the execution of other actions in the file. This chapter covers the setup and operation of the following actions.
Jumping to a Designated Action (Branch Action)The Branch action causes a jump to a designated action or to an action group. |
|||||||||||||||||||
For more information, see "Branching to Other Application Files". |
You can set the Branch action to jump to an action in the same application file, or to an action in another application file. If the Branch action jumps to an action in another application file, you can choose whether to return to the previous application file when a Return action is encountered. Branch Action Destination RulesThere are rules governing where a Branch action can jump to. If the rules are violated, Tango Server returns an error. The rules are dependent on what kind of file you use and whether you are branching to a different file. Different Application FileWhen branching to a different application file, a Branch action can only branch to an action at the outermost level. Same Application FileWhen branching to the same application file, a Branch action can branch to:
A Branch action cannot branch to:
Tango Class FileWhen using a Tango class file, the rules for Branch actions are similar to those for branching within the same application file. There is an additional rule: Branch actions in a Tango class file cannot branch outside the current method. ExamplesConsider the following partial application file:
Branching to Other Application FilesBranch and ReturnWhen a Branch action in one application file branches to another application file with the Return to next action after branch option selected, it returns to the previous application file when it encounters a Return action. However, there are certain circumstances under which the Branch action never returns, even when the Return option is selected. If a Branch action with the Return option checked branches to another application file, and then encounters a Branch action with the Return option not checked, the first Branch action never returns to the first application file, even though it encounters a Return action. That is, the lack of a Return option in the second Branch action takes precedence. Setting Up a Branch ActionWhen you drag the Branch action icon from the Actions palette into an application file, the Branch action editing window appears. To set up a Branch action
Executing a Branch ActionWhen Tango Server executes a Branch action, it jumps to the designated action. If the Return to next action after branch option is selected, Tango returns to the action following the Branch action when a Return action is encountered. Branch Action Destination NavigationYou can navigate from a Branch action to its destination action with the Go To Destination contextual menu command. When you have selected a destination for a Branch action, control+clicking the Branch action allows you to select the Go To Destination command from the contextual menu that appears. The name of the target action appears beside Go To Destination; the path to the file also appears if the action is in a different application file than the Branch action. To navigate to a Branch action destination
Conditional Action Execution (If Action)The If action is associated with an expression. During execution, Tango Server evaluates whether the conditions stated in the expression are met. If the conditions are met (true), Tango Server proceeds with a sequence of actions in the application file; if the conditions are not met (false), Tango Server proceeds with a different sequence of actions in the application file. Example: Sports Fan Web SiteConsider a Tango application file executing on a Web site for sports fans. If the user chooses to display information on hockey, the variable sport is set with the value hockey. Then, an If action evaluates the sport variable, and, if the variable has the correct value (in this case, hockey), Tango Server searches for and displays hockey information. If the user chooses to display information on football (the variable sport is set with the value football), an ElseIf action evaluates the sport variable, and, if the variable has the correct value (in this case, football), Tango Server searches for and displays football statistics. Tango Server also displays general sports news when this application is executed. The following is taken from an application file designed for our sports fan Web site:
We see that with the use of If and ElseIf actions (conditional actions), different sets of actions can be executed during the execution of an application file. General Forms of If ActionsThe If action has two related actions: Else If and Else. These actions are often used together: an If action followed by one or more Else If actions and an Else action. However, an If action can exist without Else If actions; it can also exist without an Else action. The general forms of If actions are as follows: Nested If ActionsIf actions may be nested; that is, the indented actions under an If, Else If, or Else action may contain other If, Else If or Else actions. You can have multiple levels of nesting. Performing Operations on If ActionsWorking with If actions is similar to working with grouped actions. Each If, Else If, or Else action--together with the indented actions under it--acts like a group. For information on the operations you can perform on groups, see "Working With Action Groups". Setting Up an If ActionWhen you drag the If or Else If action icon from the Actions bar into an application file, the If action editing window appears. By default, the If action editing window appears in its basic view, allowing you to create expressions quickly. An empty parameter row appears in the dialog box, ready for you to edit.
|
||||||||||||||||||
An advanced view is also available that gives you more flexibility than the basic view when specifying evaluation expressions. You change the type of If action by selecting If, Else If, or Else from the Action pop-up menu. The If and Else If action editing windows are basically the same, and you enter evaluation expressions the same way for both of them. When you select Else, however, only the Action pop-up menu is active. This allows you to change to another If action type.
Basic ViewThe basic view consists of a parameter list, which works as follows:
To specify values for the basic view parameters |
|||||||||||||||||||
The values can contain any value-returning Tango meta tags, which are substituted when Tango Server executes the action. |
|||||||||||||||||||
For more information about inserting meta tags in entry fields, see "Inserting Meta Tags". |
You can also use the Insert Meta Tag command to enter many of the commonly-used meta tags. To insert a meta tag, either click the field and choose Insert Meta Tag from the Edit menu, or control+click the field and choose Insert Meta Tag from the contextual menu that appears. |
||||||||||||||||||
To add a new parameter rowTo delete a parameter rowAdvanced ViewWhen you click Advanced in the basic view, the following happens:
There are some important differences between the basic view and the advanced view: |
|||||||||||||||||||
For more information, see "<@CALC>". of the Meta Tags and Configuration Variables manual. |
The expression entered here takes the same form as expressions specified for the <@CALC> meta tag.
Tango can take the parameters appearing in the basic view and regenerate the equivalent text-based expression in the advanced view. To regenerate the parameters from the basic view
To return to the basic view
Repeating Actions (Loop Actions)A Loop action repeats the execution of a set of actions for a given number of times or while an expression evaluates to true. In an application file, the actions to be repeated in the loop are indented under the Loop action. Example: Music StoreConsider an online music store. It allows customers to search for their favorite recordings and artists. As an additional service, this store also searches other sites for recordings and artists that it does not have in stock. A Loop action can be set up such that Tango Server goes through the sites that this store has an agreement with. For each of these sites, Tango Server searches for recordings and artists, and then updates the results and displays them to the customer. This process continues until Tango Server comes to the end of the sites. The loop ends at this point, and Tango Server proceeds to the next action outside the loop, which is to present the order information. The following is taken from an application file designed for our music store:
General Forms of Loop ActionsThere are three kinds of Loop actions:
While LoopThe While Loop takes the following general form:
A While Loop is associated with an expression. If this expression evaluates to true, Tango Server executes the indented actions listed under the While Loop action. (In this example, these indented actions include ActionA and ActionB.) When all the indented actions are executed, the expression is evaluated again. Tango Server repeats the indented actions as long as the expression evaluates to true. When the expression evaluates to false, Tango Server proceeds to the next action at the same level as the While Loop action. (In this example, it is ActionC.) For LoopA For Loop action takes the following general form:
A For Loop specifies that a group of indented actions listed under the For Loop is to be executed and repeated a number of times. (In this example, these indented actions include ActionA and ActionB.) After repeating so many times, Tango Server proceeds to the next action at the same level as the For Loop action. (In this example, it is ActionC.) |
||||||||||||||||||
Tango also includes a Break action you can use to exit a Loop action before the loop conditions for termination are met. Nested Loop ActionsLoop actions may be nested; that is, the indented actions under a While Loop or For Loop action may contain other While Loop or For Loop actions. You can have multiple levels of nesting. Setting Up Loop ActionsWhile LoopA While Loop action executes and repeats the actions in the loop (shown as indented actions) while an expression evaluates to true. When you drag the While Loop action icon from the Actions bar into an application file, the While Loop action editing window appears in its basic view, allowing you to create evaluation expressions quickly. In order for the While Loop to work properly, you must avoid the following pitfalls:
|
|||||||||||||||||||
The basic view for a While Loop action is similar to the basic view for If and Else If actions. The While Loop action editing window also has an advanced view that gives you more flexibility than the basic view when constructing evaluation expressions. For example, you can use parentheses to control the evaluation order. |
|||||||||||||||||||
This view is similar to the advanced view for If and Else If actions. For LoopA For Loop action executes and repeats the actions in the loop (shown as indented actions) for a given number of times. When you drag the For Loop action icon from the Actions palette into an application file, the For Loop action editing window appears. Set the parameters in a For Loop action as follows:
Executing Loop ActionsThe "General Forms of Loop Actions" section explains the basics of how Tango Server executes the While Loop and the For Loop. This section provides some additional information. While Loop
For Loop
Performing Operations on Loop ActionsWorking with Loop actions is similar to working with grouped actions. For information on the operations you can perform on grouped actions, see "Working With Action Groups". Exiting a Loop (Break Action)The Break action prematurely terminates processing in a loop or group action. On termination, processing continues at the next action after the loop or group. Drag the Break action icon from the Actions palette into a Loop or Group action at the point you want the loop or group to terminate. On execution, the Break action terminates the loop, and processing continues at the next action after the loop.
Ending File Processing (Return Action)The Return action ends application file processing and returns any accumulated Results HTML to the Web browser. |
|||||||||||||||||||
For more information, see "Jumping to a Designated Action (Branch Action)". |
The exception to this is if the current execution flow is the result of a Branch that had its Return to next action after branch option set. In this case, the execution returns to the action following the Branch when a Return action is encountered. |
Copyright © 1999, Pervasive Software. All rights reserved.