Related Content

Contact Information

Viewpoint Systems, Inc.
800 West Metro Park
Rochester, NY 14623
Phone: 585.475.9555
Fax: 585.475.9645

Viewpoint Data Management, LLC.
800 West Metro Park
Rochester, NY 14623
Phone: 585.475.9555
Fax: 585.475.9645

round top

bulletViewpoint News, October 2008


Tips & Techniques: Loop Termination Options

In the last Tips and Techniques, we presented some tips to enable programmatic configuration of math expressions. In this issue, you might find some new methods to terminate a loop.

 

For Loop with Break

LabVIEW 8.5 introduced a new option on the venerable For Loop.

How many times have you wanted to use a For Loop to walk through each element of an array, perform some operation on the element, and then decide if you are done and can prematurely leave the loop? Some obvious examples are scanning a string for a specific character during parsing of an instrument response and scanning a waveform for an event such as a level crossing. These situations begin with an array of known length, making the use of a For Loop an obvious choice, but end the looping at some unknown position within the array.

In many languages, notably C, there is an option to “break” out of a For Loop. While, technically, a While Loop will allow the same effect based on specific conditional tests, a key difference is that typical use of a For Loop has an input a list or array of known length.

LabVIEW 8.5 added a new type of For Loop that adds a stop conditional terminal inside the loop, almost like a While Loop and a For Loop combined. This terminal is made available by right-clicking on the loop structure and selecting the ‘Conditional Terminal’ option. (Unselecting this option removes the terminal.)

The code snippet displayed below shows a For Loop that stops when the character string finds the Character.

Note that, similar to the While Loop, at least one iteration is performed. If Character is not found, the CharIndex will be on less than the string length.