From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Michael.Reuter.HL@HeidelbergEngineering.

A new head-controlled while loop

Status: Declined

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

Hallo @ all.

 

I hope NI will implement a new head-controlled while loop in Labview 2011. This is a very useful function and I hope that many users will vote for this feature.

 

head-controlled while loop

10 Comments
tst
Knight of NI Knight of NI
Knight of NI

I didn't understand what you're asking because your use of local variables is quite confusing, but what's wrong with this:

 

Pre-con.png

 

Also, here are two additional methods to run a loop and stop on two conditions:

 

Loop.png

 


___________________
Try to take over the world!
jcarmody
Trusted Enthusiast

I'm thinking that you're troubled by the difference between a While loop (test first, then loop) and a Do-While loop (loop first, then test).  LabVIEW does the latter.  You can create the true While loop functionality by putting a Case Structure around the While Loop.

 

do while.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

altenbach
Knight of NI

No, a case structure around the while won't do. In a general implementation, the condition needs to be evaluated for each iteration before the main while loop code executes. See the comment by tst.

 

A related discussion from about 5 years ago can be found here. Apparently, this has been suggested and NI is aware of it.

 

The while loop needs to have two main sections: (1) to calculate the termination condition. (2) The bulk of the loop code that should, or should not execute. Many times the code sections are entangled and the termination condtion is based on the loop code. Only the programmer knows where to split based on the exact situation. A while loop containing a case structure can easily solve all this quite easily.

 

I am not sure if we should bloat the palettes with yet another structure that really does not add much to the mix. If it could be easily added as a configuration option to the current while loop, it would be OK, but I don't quite see how it should look like. Basically, we need some kind of splitter bar separating thet two code sections. 😉

 

Also, to keep the universe in balance, this would need to be also added to the FOR loop when the termination terminal is enabled.

A-T-R
Member

 


Also, to keep the universe in balance...

 COMPLETELY OFF-TOPIC:

 

@ altenbach:

 

I always like the way you're commenting things! It's just great how you get everything right to the point! It's too bad that one can't kudos single comments...

Michael.Reuter.HL@HeidelbergEngineering.
Member

In every C-Compiler and C++-Compiler is the head-controlled while loop a standard function. 

tst
Knight of NI Knight of NI
Knight of NI

Every C compiler also works with linear code whereas LabVIEW works with parallel code. LabVIEW is not C and constructs which are relevant in C are not necessarily relevant in LabVIEW any more than gender for objects (e.g. "la voiture") is relevant in English.

 

You didn't explain what the problem is with the proposed solutions or how you would expect such a construct to actually work. The code in the original post is not clear because it has race conditions, so you would need to account for that (e.g. by having a frame which will execute before the rest of the code) if you expect this idea to have any relevance.


___________________
Try to take over the world!
ryank
NI Employee (retired)

Although the diagrams are a bit garbled, the suggestion is very valid.  Here's an example of a good use case:

needrealwhile.jpg

In this case I was trying to pull out all of the tags with a particular pattern from a string.  Because the while loop evaluates its condition after its code, the terminating condition of a missing tag inserts an additional element into the auto-indexed array, using a case structure wouldn't help because the auto-index needs something.  At that point you are either reduced to using build array with a case structure or pruning the array after loop execution (which I do using the array subset).

tst
Knight of NI Knight of NI
Knight of NI

Ryan, I still don't see it. The code (at least the stop evaluation code) has to run. Once that runs, how do you cleanly define that you only want to execute that and not anything else? What happens if the eval code is part of the rest of the code? Do you just tell LV "ignore that last run for any outputs"? What about code which already executed (e.g. writing to disk or dequeuing? You can't tell it to "unexecute", so you have a hole which some code falls through and some doesn't.

 

 

In any case, that specific use case would probably be better implemented using Conditional auto-indexing (and its friend concat indexing might help as well in similar cases).

 


___________________
Try to take over the world!
AristosQueue (NI)
NI Employee (retired)

Ryan: If this were C code with a pretest while loop, you'd still have a problem. At that point, you'd have two calls to Match Tag, instead of one call to Match Tag, one before the loop and one inside the loop. Something like:

 

bool validData = MatchTag(.......);

while (validData) {

      Add to array...;

      validData = MatchTag(.......);

}

 

You could get the same effect in LV with two copies of MatchTag and a Case Structure around the whole loop. The addition of a pretest while loop isn't going to save you the extra work, and syntactically it would be a mess.

 

Note: I should explicitly note that I didn't write "while (MatchTag(....)) {" because that is not an option LV could ever implement without creating subdivisions of the loop structure exactly equal to the user adding a case structure inside the loop.

Darren
Proven Zealot
Status changed to: Declined

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