LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop auto index bug

I think I've found a bug (LV2009 SP1).  In the attached VI, the top loop runs indefinitely, but the bottom loop doesn't.  The problem happens on the third iteration (of the top loop), when the input to the for loop ("Row") is an empty array, but the output of the for loop tunnel ("String") keeps the value from the previous iteration.  The bottom loop seems to fix the issue by explicitly indexing the 2D array, rather than using auto-indexing on the while loop input.

 

Jaegen

Message Edited by Jaegen on 03-01-2010 04:44 PM
Message 1 of 11
(5,800 Views)

please see why the second loop can be stopped. The second loop is stopped becease "for loop" is not executed and boolen array is empty.  You can see "Boolen And" under which conditions can be true.

 

While loop auto index can not return size=0 subelement. The array index function return size=0 subelement when index > n size.

That is why the second loop can be stopped. => size=0; => for loop is not exectued;=> boolen array is empty;=> Boolen And is True. Otherwise also can not be stopped

 

 

Perhaps while loop have not function to detect the array size. The for loop may have function to detect the array size. For each iteration, it can use i to compare the array size

 

Second question, is why the empty string can not replace the exsting value in  memory in the "for loop structure". The one only can be explained by NI developer .

 

Anyway, it is beter not to use while loop for  array index.

 

 

帖子被Mechtest在 03-01-2010 09:47 PM
时编辑过了
0 Kudos
Message 2 of 11
(5,777 Views)

It does seem to be a bug.

 

In LV 2009SP1, it does seem to be holding onto the last element rather than returning the default (empty strings) when it autoindexes past the end of the array.

 

I saved the VI back to LV 8.6.1 and both loops stopped after two iterations as expected.

 

 

From, LabVIEW help:

Auto-Indexing with While Loops

If you enable auto-indexing for an array entering a While Loop, the While Loop indexes the array the same way as a For Loop. However, the number of iterations a While Loop executes is not limited by the size of the array because the While Loop iterates until a specific condition occurs. When a While Loop indexes past the end of the input array, the default value for the array element type passes into the loop. You can prevent the default value from passing into the While Loop by using the Array Size function. The Array Size function indicates how many elements are in the array. Set up the While Loop to stop executing when the number of iterations equals the array size.

 

(I highlighted the most important part in bold.)

 

 

Message 3 of 11
(5,772 Views)

Hm, i cannot confirm this. Everything seems to work as stated in the help. Thanks for pointing this out, Ravens, even with highlighting of the important part  😉

 

I checked with LV2009f3 (eng) on Windows 7 (eng) as well as LV2009SP1 (eng) on Windows Vista (ger). Both showed the same behavior.

You can make the following change for the upper loop to terminate properly:

AutoIndexingWithForLoop.png

 

This works at least for my machine....

 

Norbert

 

 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 11
(5,732 Views)

Norbert,

 

Just to check.  Did you use the VI that Jaegen posted in message #1?  Run it in LV 2009 and save it back to LV 8.6 and compare the behaviors.

 

While I certainly wouldn't recommend using the proposed method in the top loop as a means to stop a while loop (and would more explicitly stop it like you show), when I ran the original VI in both versions, I did see different behavior.  I ran it again today at work on LV2009sp1 and 8.6.1 (on XP) and again saw different behavior.  (At home was same versions on Vista Home Premium 64bit)

Message 5 of 11
(5,707 Views)

Hmmmmm, this is really odd. Sure i used the VI from Jaegen.

It works as the help states and after the  second iteration, "Row" is an empty array and stays empty. If that happens, it is no surprise to me that the upper loop is running infinitly because the for loop will not execute anymore (empty array autoindexing!). So the boolen array of the four loop will not change anymore leaving the output to {False, False}. The And Array Elements will therefore result in False as well, the loop is keeping going on......

 

I made a little test and here is what is going on:

LV 8.6 does return an empty array of booleans for the autoindexing output tunnel of the For Loop in case that the string array at the input tunnel is empty which will result in a TRUE from the And Array Elements.

LV 2009 had major changes in the memory management. I haven't found documentation on this yet, but LV 2009 returns the last array in the autoindexing output tunnel of the For Loop if it is not updated anymore.

This is why the behavior is different between LV 8.6 and 2009.

 

Norbert

 

Message Edited by Norbert B on 03-02-2010 09:21 AM
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 6 of 11
(5,696 Views)

Ok, the behavior is created because of erratic behavior of the empty string array of the autoindexing input tunnel of the while loop indeed....

 

Filed CAR #211062.

 

Norbert

   

 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 7 of 11
(5,674 Views)

I think you have a pretty accurate description as to what is going on.  But I disagree with you on  a couple points.

 

Basically the problem is centered around the inner For Loop.  When it is receiving an empty array at its auto-indexing tunnel, it is proceeding to run using the last data it had rather than not running because it got an empty array.

 

This does seem to be a problem in memory management related to the combination of loops and is not expected behavior since the For Loop is supposed to run zero times when it gets an empty array.

 

I've attached a modified version of Jaergen's original VI.  It is simplified and has a few more indicators to show that the inner For Loop is running even though it shouldn't be.

 

 

One other point, you say that if the inner for loop was not running, the boolean array would not change anymore and be leaving the output at {False, False}.

But according to LabVIEW Help

"Default Data in Loops

Loops produce default data on the first iteration when the shift register is not initialized.

For Loops produce default data if you wire 0 or a negative number to the count terminal of the For Loop or if you wire an empty array to the For Loop as an input with auto-indexing enabled. The loop does not execute, and any output tunnel with auto-indexing disabled contains the default value for the tunnel data type. Use shift registers to transfer values through a loop regardless of whether the loop executes."

 

I'd say the default data for a boolean array would be an empty array (with all the elements undefined as the default boolean of False) and not a Boolean array where exactly Two boolean elements are defined as False.

 

 

EDIT:

Thanks for filing the CAR.  It looks like you got that post in there while I was trying to work through the VI trying to correlate what you were saying with what I was seeing.

Message Edited by Ravens Fan on 03-02-2010 11:49 AM
Message 8 of 11
(5,658 Views)
This is indeed a CAR.  As was mentioned, the while loop has erratic data in an empty return that the for loop then thinks is actual data.  At that point the for loop tries to read the data and sees that it is empty and then just uses the values it previously had.  I'll make sure that this CAR gets to the right place so we can start tackling this issue.
National Instruments
Applications Engineer
Message 9 of 11
(5,647 Views)

Adding a create copy between the loops will stop the inner loop

 

 

Message Edited by paulmw on 03-02-2010 12:35 PM
Message 10 of 11
(5,623 Views)