LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
TailOfGon

For Loop with "else" case

Status: Declined

Any idea that has received less than 3 kudos within 3 years after posting will be automatically declined.

forLoopWithElseCase.png

TailOfGon
Certified LabVIEW Architect 2013
11 Comments
Darin.K
Trusted Enthusiast
You should always use shift registers for refnums, errors and any other value which you want propagated in the event of a zero iteration For Loop. The upper version of your What about..? picture (minus the case selector) would work.
TailOfGon
Active Participant

Forgot to add an explanation. Else case will be run one time when no For Loop iteration occurs.

TailOfGon
Certified LabVIEW Architect 2013
crossrulz
Knight of NI

All you have to do is use a shift regiter for the reference.  If you think about it, it makes total sense.  I'll have to see if I can dig up a good reference to this.

 

As for your extra comment, that's what a case structure if for.  It should not be merged with the for loop.  That would be too confusing.


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
elset191
Active Participant

See also: LabVIEW Minutiae (that may bite you someday)

--
Tim Elsey
Certified LabVIEW Architect
TailOfGon
Active Participant

I did not know that you can use a shift-register to pass data even without any iteration !! Thank you all for teaching me this 🙂

 

 

TailOfGon
Certified LabVIEW Architect 2013
crossrulz
Knight of NI

Here's a link to a LAVA thread on this discussion.  The link will take you to the answer.


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
altenbach
Knight of NI

> I did not know that you can use a shift-register to pass data even without any iteration !! Thank you all for teaching me this :smileyhappy:

 

They don't really "pass" any data, because both sides of the SR are the same memory location. Whatever you wire in, you can later read out. 😄

 

altenbach
Knight of NI

Well, it is not really an "else" case, but a "zero iteration" case, which would be triggered by feeding a zero to N or having any of the autoindexing input arrays be of zero size.

 

As has been mentioned by others: In the case you show, using shift registers is sufficient to maintain the error and reference data, so having zero iterations will work correctly, no special case needed.

 

The important question is now if there are any legitimate cases where we actually want some real alternative code (not just wired across!) to be executed if there are zero iterations?

At this time, I don't see a scenario where that would be useful.

TailOfGon
Active Participant

When I first posted this thread, I was expecting a full of Kudos that I can't even hold around my arms. But the reality was completely opposite Smiley Very Happy

 

altenbach,

 

Thank you for getting to this point. Even if I did not know the shift-register could do enough in my example, it does not mean 'else' case is completely useless. There are cases where you do something else other than just wiring it through. But now I think such situations are rare and a case structure can be used for that purpose. 

TailOfGon
Certified LabVIEW Architect 2013
GregR
Active Participant

Should LabVIEW do more to help users get this right? If we had a better warning system, should tunnels on these by warnings? Should refnums and errors default to creating shift registers instead of tunnels? Would that behavior only be on for loops or should while loops do it too (since while loops always run once they don't have quite the same problem but errors particularly can still be important)? Are there other types that are better served by shift registers?

 

This idea is probably not a good place to brainstorm these concepts but if you can define a good heuristic for LabVIEW to decide between tunnel and shift register, you can always post it as another idea.