spacetoon34 Posted March 5, 2007 Report Share Posted March 5, 2007 Hello, I have a problem in breaking for loop i attach the problem , there is a for loop work for 10 sec and i have a stop button i want the button to break the for loop if i pressed it please help, i use labview 7.1 thanks Quote Link to comment
Mellroth Posted March 5, 2007 Report Share Posted March 5, 2007 You should use a WHILE loop instead (actually a DO_WHILE) The FOR loop is to be used when you know how many iterations you need, it can't be stopped until all iterations have completed. /J Quote Link to comment
Tomi Maila Posted March 5, 2007 Report Share Posted March 5, 2007 QUOTE(spacetoon34 @ Mar 4 2007, 09:09 PM) Hello... Please, never use anything else than the normal font. It's annoying and it doesn't get your questions better answers, on the contrary. Quote Link to comment
spacetoon34 Posted March 6, 2007 Author Report Share Posted March 6, 2007 I need to use for loop because i want the loop to work for a limited time but i want to add an option that says that i can break the time by beaking the loop via a button Can I ???? Quote Link to comment
Tomi Maila Posted March 6, 2007 Report Share Posted March 6, 2007 QUOTE(spacetoon34 @ Mar 5 2007, 11:42 PM) I need to use for loop because i want the loop to work for a limited time but i want to add an option that says that i can break the time by beaking the loop via a button You can do this with while loop. Do { what ever you want to do } while (i < N && !stop) Quote Link to comment
Michael Aivaliotis Posted March 6, 2007 Report Share Posted March 6, 2007 http://forums.lavag.org/index.php?act=attach&type=post&id=5130 Quote Link to comment
LAVA 1.0 Content Posted March 7, 2007 Report Share Posted March 7, 2007 Hi, All this remind me this thread on NI forum : http://forums.ni.com/ni/board/message?boar...message.id=7#M7 "For loop with a break" don't exist in LabVIEW... the subject has been discussed. Do we really need these knowing that we have a while loop ? I think Michael's post answers the question. Quote Link to comment
Mikkel Posted March 7, 2007 Report Share Posted March 7, 2007 QUOTE(TiT @ Mar 6 2007, 08:09 AM) Hi,All this remind me this thread on NI forum : http://forums.ni.com/ni/board/message?board.id=features&message.id=7#M7' target="_blank">http://forums.ni.com/ni/board/message?boar...message.id=7#M7 "For loop with a break" don't exist in LabVIEW... the subject has been discussed. Do we really need these knowing that we have a while loop ? I think Michael's post answers the question. I would love for LabVIEW to support a 'break' operation in for loops (the lack of this feature is actually one of the (few) things that annoys me, when coding in LabVIEW). This way, you would elegantly be able to iterate through an array until some condition is met, and then exit the loop. Yes, I know this can be achieved by using a while loop, but not without first getting the array size, and making the 'compare with i' logic inside the while loop (and enbedding the while loop in a case, to handle if the array is empty). -Mikkel Quote Link to comment
Tomi Maila Posted March 7, 2007 Report Share Posted March 7, 2007 QUOTE(Mikkel @ Mar 6 2007, 10:31 AM) I would love for LabVIEW to support a 'break' operation in for loops (the lack of this feature is actually one of the (few) things that annoys me, when coding in LabVIEW). I propose an XNode coding challenge on writing a for loop with a break. I don't know if XNodes are capable enough but timed loop is at least partly based on XNodes... Quote Link to comment
LAVA 1.0 Content Posted March 7, 2007 Report Share Posted March 7, 2007 CITATION(Mikkel @ Mar 6 2007, 09:31 AM) This way, you would elegantly be able to iterate through an array until some condition is met, and then exit the loop.Yes, I know this can be achieved by using a while loop, but not without first getting the array size, and making the 'compare with i' logic inside the while loop (and enbedding the while loop in a case, to handle if the array is empty). Indeed ! In fact, yesterday I saw that post : http://forums.lavag.org/How-to-create-templates-t6599.html''>http://forums.lavag.org/How-to-create-templates-t6599.html' target="_blank">http://forums.lavag.org/How-to-create-templates-t6599.html and then made a "template" for what you've described right above But if some geek can make an Xnode of this, that would be great ! Quote Link to comment
Aitor Solar Posted March 15, 2007 Report Share Posted March 15, 2007 QUOTE(TiT @ Mar 6 2007, 10:52 AM) But if some geek can make an Xnode of this, that would be great ! I suppose you can create an XNode that detects if is inside a for loop, and in the generate code phase, replace that for loop with a while loop that stops with the boolean condition passed to the XNode. The hard part would be checking all the indexed array inputs to see when to stop, if the N is wired... Imagine that, after all that hard work, NI decides to add that capablity to LV's native for loops. It would be crazy! Saludos, Aitor Quote Link to comment
Aristos Queue Posted March 15, 2007 Report Share Posted March 15, 2007 QUOTE(Aitor Solar @ Mar 14 2007, 07:37 AM) Imagine that, after all that hard work, NI decides to add that capablity to LV's native for loops. It would be crazy! You're absolutely right. It wuold be crazy. So make sure to tell me if anyone does it. Then I'll make sure we never do something like for-loop-with-break. Quote Link to comment
Mike Ashe Posted March 16, 2007 Report Share Posted March 16, 2007 QUOTE(Aristos Queue @ Mar 14 2007, 05:08 PM) You're absolutely right. It wuold be crazy. So make sure to tell me if anyone does it. Then I'll make sure we never do something like for-loop-with-break. Quote Link to comment
Mellroth Posted March 16, 2007 Report Share Posted March 16, 2007 QUOTE(Mike Ashe @ Mar 15 2007, 01:21 PM) "Always look at the bright side of life..." /J Quote Link to comment
crelf Posted March 16, 2007 Report Share Posted March 16, 2007 QUOTE(JFM @ Mar 15 2007, 11:31 PM) "Always look at the bright side of life..." Quote Link to comment
Mark Balla Posted March 16, 2007 Report Share Posted March 16, 2007 QUOTE(Mikkel @ Mar 6 2007, 02:31 AM) I would love for LabVIEW to support a 'break' operation in for loops (the lack of this feature is actually one of the (few) things that annoys me, when coding in LabVIEW).This way, you would elegantly be able to iterate through an array until some condition is met, and then exit the loop. Yes, I know this can be achieved by using a while loop, but not without first getting the array size, and making the 'compare with i' logic inside the while loop (and enbedding the while loop in a case, to handle if the array is empty). -Mikkel I use a simple Stop loop utility that I keep in my user lib it allows for several stop loop contitions and also has an output that tells why the loop stoped. http://forums.lavag.org/index.php?s=&showtopic=2710&view=findpost&p=9584' target="_blank">see here Quote Link to comment
TG Posted March 16, 2007 Report Share Posted March 16, 2007 QUOTE(spacetoon34 @ Mar 4 2007, 02:09 PM) Hello,I have a problem in breaking for loop i attach the problem , there is a for loop work for 10 sec and i have a stop button i want the button to break the for loop if i pressed it please help, i use labview 7.1 thanks Can't make a 7.1 Vi since I have 8 and 8.2 installed. . Look at this jpeg. QUOTE(spacetoon34 @ Mar 4 2007, 02:09 PM) Hello, I have a problem in breaking for loop i attach the problem , there is a for loop work for 10 sec and i have a stop button i want the button to break the for loop if i pressed it please help, i use labview 7.1 thanks PS:You need to get some basic training. Quote Link to comment
Mikkel Posted March 16, 2007 Report Share Posted March 16, 2007 QUOTE(mballa @ Mar 15 2007, 03:40 PM) I use a simple Stop loop utility that I keep in my user lib it allows for several stop loop contitions and also has an output that tells why the loop stoped. http://forums.lavag.org/index.php?s=&showtopic=2710&view=findpost&p=9584' target="_blank">see here Yes, this is one way of handling it. I may be overoptimizing, but calling a sub-VI every iteration of a loop to find out if the loop should terminate just feels wrong -Mikkel Quote Link to comment
Mark Balla Posted March 17, 2007 Report Share Posted March 17, 2007 QUOTE(Mikkel @ Mar 15 2007, 04:01 PM) I may be overoptimizing, but calling a sub-VI every iteration of a loop to find out if the loop should terminate just feels wrong -Mikkel I would say you are over optimizing. In my world saving a programmer's time is a much higher priority than worrying about a few computer clock cycles. Most of the time with a modern PC you will have plenty of cpu time to spare. I doubt you can say the same about a programmer's time. Writing the same code over and over to do the same thing. Now That is just WRONG. Quote Link to comment
Mike Ashe Posted March 17, 2007 Report Share Posted March 17, 2007 QUOTE(JFM @ Mar 15 2007, 08:31 AM) "Always look at the bright side of life..." Somehow, every time I see/hear that line of that song I then "hear" it in my head as performed by Jack Nickolson at the piano in "As Good As It Gets" ....QUOTE(mballa @ Mar 16 2007, 12:31 AM) I would say you are over optimizing. In my world saving a programmer's time is a much higher priority than worrying about a few computer clock cycles. Writing the same code over and over to do the same thing. Now That is just WRONG. I would generally agree, with the exception of some LabVIEW Realtime or LabVIEW embedded applications where you are trying to flatten out the hierarchy and wring every last clock cycle out of your code. Even then I'd agree unless the specific application leaves you no other choice. Quote Link to comment
Gary Rubin Posted March 17, 2007 Report Share Posted March 17, 2007 QUOTE(Mike Ashe @ Mar 16 2007, 02:36 PM) I would generally agree, with the exception of some LabVIEW Realtime or LabVIEW embedded applications where you are trying to flatten out the hierarchy and wring every last clock cycle out of your code. Even then I'd agree unless the specific application leaves you no other choice. There are plenty of applications where driver availability precludes the use of LabVIEW realtime, yet you still need high-speed, pseudo-realtime performance. You may have noticed from many of my past posts, I'm very interested in optimizing Labview for those last few clock cycles. I work in the radar world, where data acquisition is in the high MHz, and processing loops have to be kept in the low ms. If it takes me 2 weeks to squeeze those last few milliseconds from a processing vi, it's well worth the effort if those few milliseconds mean the difference between being able to keep the whole thing on a PC in Labview vs. having to go to an embedded or C-based approach. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.