LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how break any loops...

Hi,
 
Does a equivalent of "break()" in C exist in LabView? 
 
I would like to go back to the main loop if the user hit a Key. my program has many loop of many type and i would like to leave out all of them in order to go back to the main loop when the user want. Should I check this condition in every loop???
 
in C i used a timer which check anywhen if a key is hit or not.
 
Could you help me?
 
Thanks
 
L'asticot
0 Kudos
Message 1 of 11
(3,653 Views)
Hi Jojo,

in a while loop you can check you break condition in every iteration - by using AND or OR you can wire as many conditions as you need.
In a for loop you have to use a case structure to allow a break feature: put all the code inside the case and execute this only when no break condition is met.

Be aware of limitations: these simple schemes will only 'break' the loops, but not the code inside! When the code is running very slow/ for a long time you should check your break condition in the code as well...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 11
(3,651 Views)

so there is no solution to break all the loops?

For example if i have a for loop which is in a for loop which is itself in a for loop, i must put a case structure in every loop?

it's difficult because i have no experience in Labview and i can think only in C language. And in C it is really simple. 

I have a more specifique question: how could we break a sequence structure without checking a condition in every sequence?

Thank you

0 Kudos
Message 3 of 11
(3,638 Views)
Hi Jojo,

it's always the same answer: as there is no 'break' function in LabView (IMHO this is very nice!) you have to use case checking everywhere!
You cannot break a sequence structure in the middle, you have to go htrough every frame.
But:
LabView is dataflow programming!
Consider this in your design evaluation. In most cases you don't need a sequence structure at all. Use error clusters to guarantee proper data flow!

Don't try to move bad programming techniques from C to LabView Smiley Wink
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 11
(3,631 Views)
There is in fact no way to stop a for loop in LabVIEW. Like mentionned, you can put its code in a case to stop the loop faster but it will do all the iterations before stopping. Therefore, if a loop must be stopped, then you should use a while loop.

Now to the sequence structure.
If the execution of the code depends on conditions, then you should use a state machine instead. The main purpose of  a sequence structure is to force the execution order of different parts of the code. Generally, this can be done by adding error cluster wires (or refnums...) to your VIs and by wiring them from one VI to the other. But in some cases, a sequence structure is necessary.




Message Edité par JB le 05-30-2007 11:52 AM

0 Kudos
Message 5 of 11
(3,631 Views)

ok i understand. But i don't know anything about dataflow programmation...

Could you give me a example of error clusters using? because i don't really know how labview treat the code...

thank you

 

0 Kudos
Message 6 of 11
(3,621 Views)
Hi Jojo,

LabView comes with a manual and a lot of examples!
You can also join a LabView Basics course to get you started! (Look for Basics course in the 'Academics' section of the NI website.)
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 11
(3,605 Views)
This link should help you
0 Kudos
Message 8 of 11
(3,602 Views)
First, LabVIEW is a very powerful programming language. Unfortunately, it contains some features that are not very good - like sequence structures. Sequence structures  are completely unnecessary. The correct approach is to use data dependency to gate execution, this is what is called dataflow programming. Sometimes these data dependencies occur naturally in that you need some piece of data collected or calculated in Step 1 in Step 2. But the more common form of data dependency is that you don't want to go on to Step 2 until you know whether or not Step 1 was successful. This is the job of error clusters.

An error cluster passes information from one subVI to the next and, when an error is present, often has the effect of internally disabling the execution of subVIs. To use error clusters, connect the Error Out indicator on one subVI to the Error In connector on the next subVI. Likewise, you should put error cluster connectors on most of the VIs that you create. The rule I use is That I include error clusters if the logic in the VI can create an error, or might need to be able to respond to errors that occurred elsewhere.

However, keep in mind that there are also situations where there is no data dependency between different pieces of logic. In those situations LabVIEW will happily do multiple things in parallel.

Beyond this very basic guidance, I would recommend you get a good book (several have been mentioned recently on the forum) and spend time reading posts from people who have proven their ability to answer questions and help people - look for the orange and red bars in front of their names. On this forum you have access to literally centuries of experience in working with LabVIEW. You will learn a lot.

Likewise, make a concerted effort to forget what you may have learned about programming in C, C++, BASIC, Pascal. Modula, FORTRAN, Cobol, APL or any other language. These other languages aren't bad it's just that the way you think about solving problems in them will not be helpful when working in LabVIEW. LabVIEW is a different kind of programming language and it requires a different kind of thinking.

Welcome to the ride, may it never be dull...

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 9 of 11
(3,596 Views)

thank you for your explanations.

But in this moment i need to complete a labview apllication for my training and unfortunately, i can't spend so much time to learn labview.

i'm going to try the error cluster using. it should help me.

thank you.

bye

0 Kudos
Message 10 of 11
(3,593 Views)