LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2009 for loop zero iteration bug

Solved!
Go to solution

This may have been posted before, but when a variable is wired straight through a for loop (queue references for example) and the loop iteration is set to zero, or there are no elements in an auto indexed array, the wire going straight through results in a null or zero value.

 

 untitled.png

 

untitled2.png

_____________________________
- Cheers, Ed
0 Kudos
Message 1 of 8
(4,124 Views)
Solution
Accepted by yenknip
This is not a bug, and is the behaviour of LV as far back as I can remember. To avoid this, use a shift register instead of loop nodes - this will ensure the data is passed through correctly even when iteration count = 0.
Thoric (CLA, CLED, CTD and LabVIEW Champion)


Message 2 of 8
(4,118 Views)

You always get the default value for that data type. There was a small discussion in one of Darrens nuggets (if I remember correctly).

 

Felix 

0 Kudos
Message 3 of 8
(4,111 Views)

This behavior is as old as LabVIEW's For Loop and it is no bug. It's simply how LV works.

Please note that there have been quite many KBs and similar around. The latest KB regarding this behavior can be found here

 

hope this helps,

Norbert 

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

I suppose it's because tunnels are not 'paired' in the same way SRs are.

 

I can't believe I haven't come across this before 🙂

Message Edited by yenknip on 09-08-2009 10:43 AM
_____________________________
- Cheers, Ed
0 Kudos
Message 5 of 8
(4,106 Views)

It is no "pair" when using shift registers (SR).

The SR is always the same memory location (left and right node) whereas tunnels are always seperate memory locations (aka as copy of value).

 

Norbert 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 6 of 8
(4,101 Views)

Thanks, Norbert. I was under the impression that SRs were buffered as well.

_____________________________
- Cheers, Ed
0 Kudos
Message 7 of 8
(4,086 Views)

> There was a small discussion in one of Darrens nuggets (if I remember correctly).

I didn't find it: https://forums.ni.com/t5/Community-Documents/Darren-s-Nuggets/ta-p/3524320.

 

Using a shift register is not always appropriate. Take an error wire for example; it is likely that as many of the for loop iterations should work as possible (e.g. read all calibration tables into memory). If one at the beginning fails the later ones should not. In this case, the error wire Tunnel Mode should be Indexing instead, and the zero N / no iterations scenario handled by routing the error wire around the loop and merging the array into it, sort of like this: https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Add-Merge-Errors-on-Loop-Terminal/idi-p/3202506?light...

0 Kudos
Message 8 of 8
(3,085 Views)