Conditiona​lly Indexed For Loop Terminal

Dear LabVIEW community!
Most of you, I’m sure, know and use in LabVIEW 2012 such useful and helpful feature as conditional terminal in For Loop (see it on the picture below).
But if one saves such code in previous versions of LabVIEW, then we see, that code has different look (VI Snippet was made in LV 2012, so don’t be confused – it is really code in LV 2011).
The same algorithm is made by using case structure and shift register. But the problem is that this shift register is uninitialized (1) (we have some constant (2) on the block diagram after saving file in previous version, but it is wrong constant for our case), and you know, that it can cause unexpected behavior of the program. So, if you have to convert such a code to previous versions of LabVIEW, don’t forget to check it, and initialize that shift registers.
Solved!
Go to Solution.

Wow! I had no idea this little "conditional terminal" existed. I've been doing Example B all this time, and it sometimes really causes my BDs to elongate. I don't know about you, but my programming always to contain the best examples of "The drawing will fill the space available - and then some." Now, I'll get to stick in one or two more bits before I hit the right-hand wall. Thanks.
Cameron
To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.
To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
LabVIEW Unit 1 - Getting Started
Learn to Use LabVIEW with MyDAQ

Similar Messages

  • FOR loop termination?

    Is there any way in LabView to terminate FOR loop from the inside
    before it executes N times? Something like "break" instruction in C. It
    seem like a simple question, but I couldn't find a simple solution :-).
    thanks,
    chris

    I know this is not exactly what you are asking for, but I will mention it anyway.
    There are two ways to stop a For Loop. The first is to use the auto-index like you are doing. The other is to wire a value to the N input before starting the
    loop. The loop will stop on the first occurence of EITHER of these methods. If you want the convenience of auto-indexing, but know that you will not want to
    process all of the values in the array, try to determine the quantity before entering the loop. Then wire that value to the N input. A value of 0 will prevent
    any iterations of the loop from executing.
    Good luck.
    Michael Munroe Mailto:[email protected]
    A Better Complete Development Engineering Firm
    San Mateo, CA 94403 ht
    tp://www.abcdefirm.com
    chris szybinski wrote:
    > this is exactly what I've done :-). But it would be much easier to be able to break the loop.
    > chris
    >
    > Harry King wrote:
    >
    > > In article <[email protected]>,
    > > chris szybinski wrote:
    > > >yes it is,
    > > >sometimes I need to run the loop 0 times. While Loop runs at lest one time, as the condition is checked at the end of the loop. One can build the logic to
    > > >run a While Loop 0 times, but in my case design becomes pretty complicated.
    > > >In other words I can accomplish what I want, but I hoped to simplify my VI.
    > > >best regards,
    > > >chris
    > >
    > > Perhaps you could put a select comparison function in there and send the
    > > results to the loop? WHile false, it will not run, and while true, it
    > > will. Just a thought without any background into your program.
    > >
    > > Harry
    Michael Munroe, ABCDEF
    Certified LabVIEW Developer, MCP
    Find and fix bad VI Properties with Property Inspector

  • Using a For Loop Index for Array Element Number?

    Hi.  Thanks in advance for the help.  I can't seem to find what I want to do here using the search function... probably because I don't know how to frame the question appropriately.  Ignore the title to this post cause it's probably wrong vocabulary for what I want to do.
    Here's the situation:
    I have a 2D array where the first column is the X data and each subsequent column is Y data (call it Y1...Yn).  The n-value varies from run to run (some runs have 4 columns of data, some have 20), but that is easily gathered when reading the data file.  I need to perform a number of operations on each set of data, the least of which is smoothing the data and graphing it, so I'm limiting my discussion to these 2 operations.
    What I want is a for loop structure where the indexing of the loop tracks the Y1...Yn columns, grabs each column for the iteration, performs the relevant analysis, and spits out the result, but in a stackable manner.  Thus the title; I want to use the for loop's index to mark the array element for building a new array.
    See the image attached.  A 2D array of 9 columns (X, Y1...Y8) is analyzed such that each data set, (X, Y1), (X, Y2)...(X, Y8) is bundled, graphed, run through a B-spline Fit, of which is also graphed.  I need to replace this with something that looks like the for loop structure shown.  
    I just don't know how to get those two data bundles [(X, Yi) and it's smoothed pair] out of the for loop in a stacked set from every iteration of the for loop.
    Again the title, I think I want to build a new array where i use the index of the for loop to control the entries of the new array.  But I can't see how to do that.
    Any help would be appreciated.
    Attachments:
    NeedForLoopForThis.PNG ‏30 KB

    Hello H.R. Dunham, and welcome to the forum!
    It seems that you may be looking for Auto-Indexing, a basic feature of loops in LabVIEW.  You'll need to transpose your array before wiring it into the for loop, as elements are auto-indexed by row before column, but at that point you should be able to operate on each column and output an array of n cluster elements corresponding to your input columns.  Auto-indexing tunnels look like brackets to indicate each element will be indexed automatically- this should be the default when wiring an array into a for loop or when wiring anything out of a for loop.
    As for how to build your pairs, I suggest removing the X column and creating a "starter" cluster containing your X data and placeholder Y data before entering your "Y" processing loop.  Use the bundle by name function in the for loop to insert your processed column data into the cluster and auto-index the cluster output. Flow would be something like this:
    1) Gather data
    2) Split X and Y using standard array operations
    3) Create "template" cluster with shared X data
    4) Pass template cluster and Y-column array into an auto-indexed for loop.
    5) Insert processed Y data into cluster inside loop.
    6) Auto-index cluster data out of loop.
    This tutorial is probably also a good place to get started:
    Getting Started with NI LabVIEW Module 3: Loops
    http://www.ni.com/white-paper/7528/en/
    Hope that helps!
    Regards,
    Tom L.

  • Conditional Loop Terminal and Autogrow

    When changing a for loop terminal from indexing to conditional, the for loop and any containing structures expand even when they are not set to Auto Grow.
    When selecting multiple conditional tunnels and and choosing Vertical Compress from the Distribute Objects menu, the tunnels are compressed as if they don't have condititonal terminals.
    Are either of these bugs known or corrected in LabVIEW 2013?  I could not find anything on NI.com when searching for "conditional tunnel autogrow".
    Thanks,
    Matt
    Attachments:
    Conditional Terminal Auto Grow bug.vi ‏6 KB

    Matt,
    A Very nice example of unexpected behaviour!
    Steps to reproduce:
    Open Matt's attachment in LabVIEW 2012  (12.0f3 Windows 32 on Win 7 64)
    Right-click the loop and verify Autogrow is not checked
    Right-click the top output tunnel and select Tunnel mode>>Conditional.   Loop does not respect the autogrow setting! 
    Lasso both output tunnels and Ctrl+D (or optionally, click Distribute items>>Vertical Compress)  Conditional glyphs are not respected in allignment
    Select the "Top" tunnel and Ctrl+Shift+J (Move to back)  What kind of tunnel is that now? I'd really hate to debug that one.
    Really Really hate to debug that one! Run VI Analizer! No overlapping objects!
    Sounds like a small oversight-- but a deadly potential for breaking code that is impossible to find without a divining rod!
    BOLO (Be on the lookout) for this type of bug.
    Jeff

  • LabVIEW 6.1 If For Loop count terminal is zero then value going through the loop is not passed on to the output of the loop

    Hello, one of our customers just encountered an execution error in a vi running under LabVIEW 6.1, which doesn't exist under LabVIEW 5.1 or 6.01. I have a simple vi that has two encapsulated For Loops. Two string arrays go in, one goes out of the outer loop. Inside the outer loop the first array is indexed. The string which results from this indexing is compared with all other strings from the second string array in the inner loop. If it matches one of the strings of the second array, it is not outputted, otherwise this string goes through the inner For Loop to the output of the inner loop and from there to the output of the outer loop. The count
    terminal of the outer/inner loop is connected to the Array Size of the first/second string array. If the second array is empty, that means that the element in test from the first arry cannot match anything from the second array, so the element in test is send to the output of the inner loop and from there to the output of the outer loop. This works fine in LabVIEW 5.1 and 6.01, but NOT in LabVIEW 6.1. In LabVIEW 6.1 the inner loop is never executed if the count value is zero (which is correct), but the data line running through the loop is not executed either, which is different to what LabVIEW 5.1 and 6.01 do. There, the input string is sent to the output of the inner loop correctly even if the loop counter is zero. The solution is easy - I just have to connect the output of the outer loop to the data line BEFORE it enters the inner loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is supposed to be a feature, but it brings some incompatibility in programming between the
    different LabVIEW versions.
    Best regards,
    Gabsi

    Hi,
    When a for-loop runs zero times, all outputs are 'undefined' (and should
    be).
    Besides, how would LV know what the output of a not executed routine should
    be?
    It might be handled differently in LV5 and LV6, which is unfortunate. In
    both cases, the result is undefined.
    It's not a bug. It's just something that should be avoided in any LV
    version.
    > The solution is easy - I just have to connect the
    > output of the outer loop to the data line BEFORE it enters the inner
    > loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is
    In some cases this does the trick. But if the data is changed in the inner
    loop, this will effect the results if the N is not zero.
    Technically, I think the output in this construction is also 'undefined'.
    But LV handles this as expected / desired.
    Another solution is to use a shift register. If N is zero, the input is
    directly passed through to the output.
    Regards,
    Wiebe.
    "Gabs" wrote in message
    news:[email protected]...
    > LabVIEW 6.1 If For Loop count terminal is zero then value going
    > through the loop is not passed on to the output of the loop
    >
    > Hello, one of our customers just encountered an execution error in a
    > vi running under LabVIEW 6.1, which doesn't exist under LabVIEW 5.1 or
    > 6.01. I have a simple vi that has two encapsulated For Loops. Two
    > string arrays go in, one goes out of the outer loop. Inside the outer
    > loop the first array is indexed. The string which results from this
    > indexing is compared with all other strings from the second string
    > array in the inner loop. If it matches one of the strings of the
    > second array, it is not outputted, otherwise this string goes through
    > the inner For Loop to the output of the inner loop and from there to
    > the output of the outer loop. The count terminal of the outer/inner
    > loop is connected to the Array Size of the first/second string array.
    > If the second array is empty, that means that the element in test from
    > the first arry cannot match anything from the second array, so the
    > element in test is send to the output of the inner loop and from there
    > to the output of the outer loop. This works fine in LabVIEW 5.1 and
    > 6.01, but NOT in LabVIEW 6.1. In LabVIEW 6.1 the inner loop is never
    > executed if the count value is zero (which is correct), but the data
    > line running through the loop is not executed either, which is
    > different to what LabVIEW 5.1 and 6.01 do. There, the input string is
    > sent to the output of the inner loop correctly even if the loop
    > counter is zero. The solution is easy - I just have to connect the
    > output of the outer loop to the data line BEFORE it enters the inner
    > loop. But: I don't know if this is a LabVIEW 6.1 bug or if it is
    > supposed to be a feature, but it brings some incompatibility in
    > programming between the different LabVIEW versions.
    > Best regards,
    > Gabsi

  • While loop and for loop condition terminal

    Hello friends,
    I am using labview 8.6. The condition terminal of the while loop and conditional for loop is behaving in just the opposite way.
    When i wire a true to the condition terminal of my loop, the while loop continues to run when I click on run. when I wire a FALSE, it stops.
    Is there any setting change that I have to make it to get it work properly.
    Please suggest on this.
    Thanks and regards,
    Herok

    Please do NOT attach .bmp images with the extension changed to .jpg to circumvent the forum filters!
    Herok wrote:
    I am sending you the VI. I am not sure if this would help you because only in 2 computers this behaviour is seen. In others, it works as it is supposed to work.
    Whatever you are seeing must be due to some corruption or folding error. It all works fine here.
    To make sure there are no hidden objects, simply press the cleanup button which would reveal any extra stuff (which is obviously not there). Does it fix itself if you click the termination terminal an even number of times? What if you remove the bad loop and create a new one?
    Could it be you have some problems with the graphics card and the icon of the conditional terminal does not update correctly?
    Whay happens if you connect a control instead of a diagram constant?
    What is different on the computers where it acts incorrectly (different CPU (brand, model), #of cores, etc.) 
    LabVIEW Champion . Do more with less code and in less time .

  • For loop indexing?

    Is it possible to change indexing step in labView "For Loop" structure? By
    default this value is 1, and I need to make a step value different from "1"
    like in C example:
    for (index=0; index < 100; index++) {}; // step=1
    for (index=0; index < 100; index=index+3) {}; // step=3
    Sergey Yakovlev, Berlin,
    [email protected]

    Hallo, Sergey,
    Du (yakovlev) meintest am 21.09.01 zum Thema for loop indexing?:
    > Is it possible to change indexing step in labView "For Loop"
    > structure? By default this value is 1, and I need to make a step
    > value different from "1" like in C example:
    > for (index=0; index < 100; index++) {}; // step=1
    > for (index=0; index < 100; index=index+3) {}; // step=3
    What about
    j:=i*3
    and i is incremented by 1
    Greetings!
    Helmut
    Please excuse my gerlish!

  • Why are date and time strings lost when indexing an array in a for loop

    Hi, 
    I have an application where i'm reformatting data from a spreadsheet for graphical display on a LabVIEW dashboard.
    the original spreadsheet has date and time values in separate columns, and i'm merging them and converting to a timestamp value.  But something's not working.  Does anyone know why the string value is lost when the array indexes into this for loop?
    Attachments:
    failed array index.png ‏142 KB

    Can you attach your VI with some typical values? (e.g. create in indicator on the 2D array, run your VI, then turn the indicator (now containing data) into a diagram constant). Place the FOR loop related code and that diagram constant into a new VI and attach it here.
    How many times does the FOR loop run? Could it be that the last element of each 1D array is an empty string? (unless you put a wait inside the FOR loop, you'll never see the other elements in the probe)
    LabVIEW Champion . Do more with less code and in less time .

  • Indexing data on a for loop to overlay data on a xy graph

    I am using express VI's to measure both voltage and current data in a For Loop. I want to plot a current vs voltage graph but have each iteration of the loop overlay the others as if it were its own independent data set. I have been unable to bundle the data and convert it into a xy graph because of the number of elements, 3 for the bundle and 2 for the graph. I need a method to index the dynamic data wires so that I can overlay them.

    Hello,
    After reading the thread, it sounds like you're looking for a chart-like graph - I have attached an example with illustrates this.  Keep in mind that "graphs" in LabVIEW generally plot arrays of data (in the case of an XY graph, you pass a cluster which contains an X and Y array).  The example behaves like a chart by building an array one data point at a time (in this case both an X and Y array of course) on each iteration of a loop, and displaying the data at each loop iteration - this gives the look and feel of a chart which accumulates data.  It is attached in version 7.1 - hopefully you have that version or later to open it.  I have also attached a program which shows how to plot multiple data sets on an XY graph, in all 3 current formats accepted by the XY graph - it's attached in version 8.0 because the ability to plot complex data to an XY graph was added to version 8.0, and it illustrates this as well.
    Best Regards,
    JLS
    Best,
    JLS
    Sixclear
    Attachments:
    XY Chart-like Example.vi ‏24 KB
    XYGraphWithArbitrarilyManyPlots.vi ‏32 KB

  • Index out of Bounds Exception in for loop.

    Occasionaly with the code below, i get an index out of bounds error, index 1, size 1, however the for loop should ensure that it never calls the getActorLocation method if the index is the same size as the arrayList size.
    Im having one of those days, and i just cant see what error i have made.
    Perhaps i need coffee? lol
    Cheers
    James
    private void checkMemoryIntegrity(){
            Actor actor = actorList.get(actorIndex);
            ArrayList<Integer> inRangeList = getActorsInMemoryRange(actor, actor.getRange());
            inRangeList.trimToSize();
            for (int i = 0; i < inRangeList.size();i++){
                if (inRangeList.size() != 0){
                    actor = brainState.getActorLocation(i); //<<<<<<<<< problem line
                    if (!actorList.contains(actor)){
                        brainState.actorLocations.remove(i);
    public ArrayList <Integer> getActorsInMemoryRange(Actor actor, int range){
            int i = 0;
            int x = actor.getX();
            int y = actor.getY();
            ArrayList <Integer> inRangeList = new ArrayList <Integer> ();
            Actor compActor;
            while (i< brainState.actorLocations.size())
                compActor = brainState.getActorLocation(i);
                int xDist = x - compActor.getX();
                if ( (xDist >= (-1) * range) && (xDist <= range) ){
                    int yDist = y - compActor.getY();
                    if ( (yDist >= (-1) * range) && (yDist <= range) ){
                        inRangeList.add(i);
                i++;
            return inRangeList;
        }

    I was thinking it might be easier to do it this way:
    Iterator<Actor> i = actorLocations.iterator();
    while(i.hasNext())
        if (!actorList.contains(i.next())) {
            i.remove();
    }It sounds like you have an equals() method which compares the x and y locations of the actor. If not then you will have to enclose the remove in an if block which compares the actor location. Does that make sense?
    Edit: contains uses the equals method.
    Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that
    (o==null ? e==null : o.equals(e)).Edited by: Edward_Kimber on May 23, 2008 11:43 AM

  • For loop array index not from 0

    HI!
    I have an array that is wired into a For Loop. Inside the For Loop there is already a single Array content available as there is this autoindexing feature (?). I do want to change the Array from a certain position different from 0 onwards to the end e.g. change positions 4, 5 and 6 in a for loop executing 3 times. But the for loop and the autoindexing feature start at 0. Can I change this in an elegant way. At the moment I'm running thru the hole array and begin changing at a certain position.

    Yes, disable autoindexing on the tunnel and use "index array" inside the loop. Use [n]+4 as index and wire a "3" to the loop count in your particular example.
    If you want to keep the entire array and just replace a few elements with updated values, the array needs to be fed in via a shift register. Write the new elements at the desired position using "replace array subset" (see attached very simple example).
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ReplaceSomeArrayElements.gif ‏3 KB

  • How to index a array to give it to for loop for one value at a time sequence to be ensured

    I need to give one number from a array at a time to a for loop. means the for loop have to execute one number at a time  from a array of numbers. How to do it

    Ranjeet,
    Ranjeet_Singh wrote:
    But question is same only. is in it ?
    With all due respect, NO.
    Please make sure you know what you are talking about before blatantly countering someone else's comment. Can you prove that your vi and TiTou's snippet will do the same thing?
    Beginner? Try LabVIEW Basics
    Sharing bits of code? Try Snippets or LAVA Code Capture Tool
    Have you tried Quick Drop?, Visit QD Community.

  • I have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    i have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    Hi fais,
    Following through with what JB suggested. The steps involved in replacing the inner for loop with a while loop are outlined below.
    You can replace the inner for loop with a while by doing the following.
    1) Right-click of the for loop and select "Repalce" then navigate to the "while loop".
    2) Make sure the tunnels you where indexing on with the for loop are still indexing.
    3) Drop an "array size" node on your diagram. Wire the array that determines the number of iterations your for loop executes into this "array size".
    4) Wire the output of the array size into the new while loop.
    5) Set the condition terminal to "stop if true".
    6)Drop an "OR" gate inside the while loop and wire its output to the while loops condition terminal.
    7) C
    reate a local of the boolean "stop" button, and wire it into one of the inputs of your OR gate. This will allow you to stop the inner loop.
    8) Drop a "less than" node inside the inner while loop.
    9) Wire your iteration count into the bottom input of the "less than".
    10) Wire the count (see step 4 above) into the top input of the less than. This will stop the inner loop when ever the inner loop has processed the last element of your array.
    Provided I have not mixed up my tops and bottoms this should accomplish the replacement.
    I will let others explain how to takle this task using the "case solution".
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • For-Loop Bug in LV7.1

    There is a bug in LabVIEW 7.1 where you have a for-loop, a constant outside
    the loop, a constant inside the loop and a subtraction of the two constants.
    What you have to do to see the bug is:
    - Place a for-loop on the diagram
    - Wire a constant with any value to the count terminal
    - Place a constant on the diagram outside the for-loop, use any postive
    number
    - Place a constant inside the for-loop, use any positive number
    - Place a substract-icon inside the for-loop
    - Wire the constant outside the loop to the substract-icon
    - Wire the constant inside the loop to the substract-icon
    - Wire the result of the substraction to the output of the loop and disable
    indexing
    - Wire the input of the constant outside the loop directly to another output
    of the
    loop and disable indexing
    - Probe the output of the subtract.
    - Run VI
    What you will see is that the output constant is treated as 0
    Same thing with addition, multiplication, division...
    When you change the outside constant to a control it works.
    When you remove the direct output from the outside constant through the loop
    then it works.
    This has been submitted to NI as a bug report, so hopefully there will be a
    fix soon.

    Hi,
    Isn't this exactly the same bug as the bug reported a few days ago ("Major
    bug in LabVIEW math", by damsem)?
    It was painfull enough the first time...
    Regards,
    Wiebe.
    "Konima" wrote in message
    news:[email protected]..
    > There is a bug in LabVIEW 7.1 where you have a for-loop, a constant
    outside
    > the loop, a constant inside the loop and a subtraction of the two
    constants.
    >
    > What you have to do to see the bug is:
    >
    > - Place a for-loop on the diagram
    > - Wire a constant with any value to the count terminal
    > - Place a constant on the diagram outside the for-loop, use any postive
    > number
    > - Place a constant inside the for-loop, use any positive number
    > - Place a substract-icon inside the for-loop
    > - Wire the
    constant outside the loop to the substract-icon
    > - Wire the constant inside the loop to the substract-icon
    > - Wire the result of the substraction to the output of the loop and
    disable
    > indexing
    > - Wire the input of the constant outside the loop directly to another
    output
    > of the loop and disable indexing
    > - Probe the output of the subtract.
    > - Run VI
    >
    > What you will see is that the output constant is treated as 0
    > Same thing with addition, multiplication, division...
    >
    >
    > When you change the outside constant to a control it works.
    > When you remove the direct output from the outside constant through the
    loop
    > then it works.
    >
    > ----
    > This has been submitted to NI as a bug report, so hopefully there will be
    a
    > fix soon.
    >
    >

  • 1D Array Of String To For-Loop

    Hi fellow engineers,
    I'm new to LabVIEW.
    I got a question,
    If I got a 1D array of string and I want to loop my program to the same number of times (Iteration) in conjunction with the numbers of sub-folders generated by the "list folder" function. How can I do it?
    Any help is greatly appreciated.
    Solved!
    Go to Solution.
    Attachments:
    Capture.PNG ‏7 KB

    Wire the string array to the border of the for loop. LabVIEW will automatically iterate through each element of the array; you should not wire anything to the N terminal of the for loop. This is the default behavior for arrays entering a loop; if you do not want auto-indexing, right-click on the tunnel (where the array enters the loop) to change the behavior.

Maybe you are looking for