LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
Megoorda

For Loop input and output tunnels

Status: Declined
Zero-iteration defaults is a well defined and sometimes desirable behavior of the For Loop. Correctly programming with a Case Structure or with Shift Registers is sometimes necessary.

When for Loop Executes zero times the output tunnels will gave its default values.

Which will result unexpected errors,especially for resources reference tunnels or classes. 

So the idea is to add an zero execution case of the fore loop to connect terminals as default, Which will minimize the time of making an case and put the fore loop in.

 

 

Code Case:

 

 1.png

 

9 Comments
Intaris
Proven Zealot

Just use a shift register and initialise it ont he left-hand side.

crossrulz
Knight of NI

This is a very common bug that we have all ran into.  But I don't think it is worth complicating the loop by adding a "0 iteration" case.  If you need to make sure the loop runs at least once, change it to a While loop.  Otherwise just use shift registers like the rest of us have learned to do.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Megoorda
Member

You are right in some cases, but in a another cases the shift register will effect the results if the for loop if didn't executes zero time because with tunnel it will take the first value always but with shift register it will take previouse iteration value which will change results,and about using while loop, while loop not performance efficient as for loop and that what made IN to add condition to"for loop" while "while loop" can make this.

and thanks for comments.

Intaris
Proven Zealot

If you want the shift register to be invariant on input you need to program it that way.  It's the easiest solution to your problem.

Megoorda
Member

The best solution as i see is to put the for loop in a case structure to skip it at n=0 cases.

Intaris
Proven Zealot

That actually causes extra overhead for ALL iterations of the case structure (check if n=0) and is perhaps not the most efficient method.

paulmw
Active Participant

 ...but in a another cases the shift register will effect the results if the for loop if didn't executes zero time because with tunnel it will take the first value always but with shift register it will take previouse iteration value which will change results...

 

You don't have to use the shift register inside the loop.  Check out this example that will allow a different value on the output if the loop executes 0 times.

 

shiftreg.png

 

 

Megoorda
Member

You are totally right with your code, and also the case method (I had mentioned) works, so I will benchmarks the two methods to check which one is more performance efficient.

And thank you very much for your interest.

JordanG
NI Employee (retired)
Status changed to: Declined
Zero-iteration defaults is a well defined and sometimes desirable behavior of the For Loop. Correctly programming with a Case Structure or with Shift Registers is sometimes necessary.