Flow Control Step Types

TestStand 2019 Help

Edition Date: May 2019

Part Number: 370052AA-01

»View Product Info
Download Help (Windows Only)

Purpose

This example demonstrates using the Flow Control step types to control sequence flow. These step types include If, Else If, Else, For, For Each, While, Do While, Select, Case, Break, Continue, and End.

Example File Location


Open Example

<TestStand Public>\Examples\Built-In Step Types\Flow Control Step Types\Flow Control Step Types.seq

Highlighted Features

Flow Control step types

Major API

None

Prerequisites

None

How to Use This Example

The example sequence file demonstrates several methods for controlling sequence flow.

If, Else If, and End

The Prompt for option for If/ElseIf/Else step prompts you to click one of three buttons, and each launches its own message popup that indicates the button you clicked. The If step determines whether you clicked the Option A button. If the step evaluates to True, the sequence executes the steps that immediately follow the If step. If the step evaluates to False, the sequence continues to the first Else step, which in this case is an Else If step.

The Else If step behaves the same as the If step and determines whether you clicked the Option B button. If the step evaluates to True, the sequence continues executing until it encounters another Else step or encounters an End step. If the Else If step evaluates to False, the sequence executes the next Else step or continues to an End step if no additional Else steps exist.

When a sequence encounters an Else step, the sequence always executes all steps that follow the Else step. You can only use one Else step for each If step, but you can use multiple Else If steps.

Select and Case

The Prompt for option for Select/Case step prompts you to click one of three buttons, and each launches its own message popup that indicates the button you clicked. The Select step determines which button you clicked. Two or more Case steps always follow a Select step. You can specify multiple values for a single case using an array, such as {"y","yes"}. All the steps contained in a Case block execute, depending on the value the Select step evaluates. The End steps specify the end of a Case block or a Select structure.

For

The For step executes a block of steps multiple times. The For Loop edit tab on the Step Settings pane specifies that the For step begins with the Locals.index variable set to 0. The loop continues until the value of the Locals.index variable is greater than or equal to the value you specify. Each time the For step executes, the Locals.index variable increments by 1. Therefore, the Beep at done determined by loop index step in the For block executes the specified number of times and uses the increasing index.

For Each

The For Each step behaves like the For step but iterates over every element in an array rather than iterate depending on a specified condition. The Locals.CurrentMembers variable is an array that specifies three elements, so the steps in the For Each block execute three times. The current element that the loop is iterating on is stored in the Locals.CurrentName property. This setting is specified in the ForEach loop tab of the step settings of the For Each step.

Do While

The Do While step defines a block of steps that always execute at least once. The DoWhile Loop edit tab on the Step Settings pane specifies an expression that the Do While step evaluates after all the steps in the Do While block execute. If the expression evaluates to True, the steps in the Do While block execute again. If the expression evaluates to False, the sequence continues to the next step.

While

The While step defines a block of steps that execute when an expression specified on the While Loop edit tab on the Step Settings pane evaluates to True. If the expression evaluates to False, the sequence continues to the next step. The While loop differs from the Do While loop because the While loop evaluates its expression before each iteration and not after each iteration. Therefore, the steps in the While block might never execute.

Break and Continue

The Break step terminates a For, For Each, While, or Do While loop or a Case block. When a sequence encounters a Break step, the sequence exits the block and continues to the next step.

The Continue step terminates the current iteration of a For, For Each, While, or Do While loop and prompts the sequence to begin the next iteration of the loop.

Note Note  In addition to Flow Control step types, you can also use preconditions or post actions step properties to control sequence flow.

An advantage of using step properties is that the sequence can use fewer steps. In addition, the flow control logic is attached to the step. For example, if you specify a precondition of Locals.PowerSupplyOn == True for a step, the precondition remains attached to the step even if you move or copy the step to a new location. A disadvantage is that the sequence flow logic is not immediately visible when viewing the sequence. You can make flow control more visible by using preconditions on separate Goto steps and using Label steps as branch targets. However, the functionality you create in this way, such as loops or conditionally-executed blocks of steps, is embedded in the precondition expressions and branch targets, and requires anyone who reads the sequence to review the preconditions and branch targets to understand the flow control.

An advantage of using separate Flow Control steps is that the flow control logic is visible in the sequence it is expressed in separate steps that identify the flow control operations the steps perform. In addition, applications typically display the flow control structures you create with Flow Control steps with indentation and grouping bars that improve the readability of the sequence. Furthermore, because Flow Control steps operate on blocks of steps demarcated with separate End steps, you do not need to specify specific steps as branch destinations, so you can more easily edit and rearrange steps because you do not need to update branch destinations.

You can use step properties, separate Flow Control steps, or both, depending on which functionality best suites the requirements of an application.

WAS THIS ARTICLE HELPFUL?

Not Helpful