LabVIEW Idea Exchange

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

Replacing loops should retain the conditional terminal if appropriate

Status: New

Re-opening because LabVIEW NXG has been discontinued.

We can easily replace a FOR loop with a WHILE loop and vice versa and most features are retained in a reasonable and expected manner. (For example if there is an indicator wired to [i], it will still be connected after replacement).

 

There is one annoying exception: The conditional terminal is completely ignored.

 

For example:

 

Case 1 (FOR -> WHILE)

We have a FOR loop with a conditional terminal wired to a boolean condition. If we replace that FOR loop with a WHILE loop, we probably would expect the conditional terminal be still connected in the same way. This is not the case. We get a dangling broken wire and a new, now disconnected conditional terminal.

 

Case 2 (WHILE -> FOR):

We have a WHILE loop and replace with a FOR loop. If the conditional terminal is wired to some real code, it should automatically retain the conditional terminal in the same place. (If the conditional terminal is not wired in the while loop, the FOR loop should not show the conditional terminal).

 

As a practical example, let's look at my old inverse erf draft posted here long ago. One flaw is the fact that there is no limit on the number of iterations so it might get stuck with a misbehaving function. In the old days, we would add another comparison with [i] and OR to the termination condition (lots of extra code, new loop needs to grow in size). A cleaner solution is to replace the while loop with a FOR loop, leaving the conditional terminal in place as-is, and wire a reasonable iteration limit to N (little extra code (just one diagram constant!), loop can remain at the same size). Here Case 2 would simplify the transition.

 

SUGGESTION: If we switch loop flavors using the "right-click..replace" mechanism, the conditional terminal wiring should be retained in a reasonable way.

7 Comments
AristosQueue (NI)
NI Employee (retired)

When converting For Loop to While Loop, should the code that used to stop the For Loop be generated? In other words, should nodes be added that calculate the value of N before the loop starts and then a comparison added for testing whether i is greater than or equal to N inside the While Loop?

tst
Knight of NI Knight of NI
Knight of NI

AQ, I don't know the answer to your question (although I would probably say no, because now that we have the conditional terminal in a for loop, we no longer need the while loop equivalent), but if it is yes, then a case structure should be added around the loop to handle the zero iterations case.


___________________
Try to take over the world!
Daklu
Active Participant

@AQ

 

I don't think so.  If the For Loop doesn't have logic wired to the Stop terminal then I don't think the While Loop should either.  If I'm changing from a For Loop to a While Loop, it's probably because I realized I don't have prior knowledge of how many iterations I'll need executed.  I'll be deleting the auto-generated code more often than not.  Besides, adding auto-generated code to a block diagram is sure to mess up my layout somehow.  For those instances where I do want the exact same functionality in a While Loop it will be faster for me to add my own code than fixing the layout.

Darren
Proven Zealot

I'm going to try to get Quick Drop Replace to behave in this manner (replace For Loop with While Loop and vice versa, and persist conditional terminal presence and wiring) in LabVIEW 2014.

Darren
Proven Zealot

Oops, spoke too soon. "Replace with While Loop" and "Replace with For Loop" are not currently available in VI Scripting for For Loops and While Loops, respectively. I have posted an idea here to get them added. But until they do, I will not be able to implement this idea for Quick Drop.

Darren
Proven Zealot
Status changed to: Completed

Available in LabVIEW NXG. Replacing a For Loop with a While Loop will retain the conditional terminal (if present) and its wiring. Replacing a While Loop with a For Loop will also retain the conditional terminal and its wiring.

Christina_R
Active Participant
Status changed to: New

Re-opening because LabVIEW NXG has been discontinued.


Christina Rogers
Principal Product Owner, LabVIEW R&D