Jump to content
Sign in to follow this  
spacetoon34

Break for loop

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 ????

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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! :shifty:

Saludos,

Aitor

Share this post


Link to post
Share on other sites

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! :shifty:

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. :shifty:

Share this post


Link to post
Share on other sites

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. :shifty:

post-5877-1173200843.pngpost-5877-1173200843.pngpost-5877-1173200843.pngpost-5877-1173200843.png

Share this post


Link to post
Share on other sites

QUOTE(JFM @ Mar 15 2007, 11:31 PM)

"Always look at the bright side of life..."

lips_sealed.gif

Share this post


Link to post
Share on other sites

QUOTE(spacetoon34 @ Mar 4 2007, 02:09 PM)

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.

Share this post


Link to post
Share on other sites

QUOTE(mballa @ Mar 15 2007, 03:40 PM)

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 :blink:

-Mikkel

Share this post


Link to post
Share on other sites

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 :blink:

-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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.