LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange behaviour of a for Loop

Hi there,

I'm new in LabView and I try to do a Testapplication, but there are some problems with the for loops in my vi.

If I unconnect the "N" Input no error appears, and the Value for this is always set to 6, even if I unconnect the for Loop?

What can I do to solve my problem.

Attached the vi, the problem is in the main sequence on sheet 6 of 7 the main for loop there has always the value 6!

Thanks a lot for help

I'm using labView 6.0i

Markus
Download All
0 Kudos
Message 1 of 3
(2,667 Views)
For Loops also can get their execution count from an array that is passed through it's border. This is called 'Auto Indexing' and can be enabled or disabled for each array going into or out of a loop. (this works on While loops also) Notice the tunnels look different, the white square with the brackets indicates that it is auto indexing the array.

So in your case, the two arrays going into the For loops on the right hand side of the loops is setting the number of times the loop will iterate. With both the 'N' terminal and an autoindexing array going into the loop, the loop will run the number of times of the smaller number.

So if you always want the loop to run 6 and 9 times, you'll need to disable auto indexing by right clicking on the arrays tunne
l and select "Disable Indexing". You will then have to manually index through the arrays using the 'Index Array' function.

Hope that all made sense. Quoted below is the bit from the LabVIEW help about Auto Indexing.

Ed

"If you wire an array to a For Loop or While Loop, you can read and process every element in that array by enabling auto-indexing. When you wire an array from an external node to an input tunnel on the loop border and enable auto-indexing on the input tunnel, elements of that array enter the loop one at a time, starting with the first element. Right-click the tunnel at the loop border and select Enable Indexing or Disable Indexing from the shortcut menu to enable or disable auto-indexing. Auto-indexing for While Loops is disabled by default."


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 2 of 3
(2,667 Views)
Markus,

A for loop runs the maximum of the the value wired to N or the maximum number of elements in an autoindexing array. Your VI has an autoindexing array connected at the right side. This array is generated in frame 5 from a for loop which executes 6 times. This is also why you do not get an error when you disconnect the N terminal.

Most experienced LV programmers prefer to use state machines for the types of programs you have. A state machine is basically a while loop containing a case statement. Look at the examples and search for "State Machine" to get more information. The state machine architecture is much more versatile than the sequence structure.

Lynn
Message 3 of 3
(2,667 Views)