Hi there,
(Please let me know if this post is duplicated)
I was looking for possible way to implement a While-Do loop from text programming language in LabVIEW, and I understand that the While Loop in LabVIEW is similar to a Do-While loop (Running the code in the loop first before checking the condition).
Here's a simple scenario:
I was to translate the following code in LabVIEW:
while (x > 0) {
// Loop Code goes here x--;
// Note: Bear in mind the above line is just for simple scenario.
// There are cases where code within the loop involves calculate x value
}
While I already have an idea in how to implement this in LabVIEW, I came across a LabVIEW Help link (along with other forum posts with solution) that suggested using Case Structure inside a While Loop.
http://zone.ni.com/reference/en-XX/help/371361N-01/lvhowto/preventing_code_execution/
Which means the code will be something like this:
![Old.png Old.png]()
Although it is not wrong, but I believe this can be inefficient especially when running lots of iterations and execution speed is a concern. The While Loop will always running the Case Structure for every iteration and may introduce some overhead.
So as alternative, instead of placing the Case Structure inside a While Loop, how about placing the While Loop inside a Case Strcuture?
![New.png New.png]()
With that you can run the Case Structure only once to check the condition first, before running the While Loop if the condition is true.
After tried running both methods, it seems that the alternative method runs faster than the method described in the LabVIEW Help site.
I've attached the code below so that you can give it a try.
Should you have any comments or a much better alternative to implement a While-Do loop in LabVIEW, feel free to discuss and share with us.
Thank you.
Regards,
Ong Ee Lim