LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop For loop execution

Hi..
Is it possible to stop a For loop until a condition is satisfied. Actually I want to make a pause after the iteration value of 3 and then make pause. After I press a button or something else, the for loop should start running from the iteration 4. Say N value is 5.
Is it possible ? Or this idea is a wrong one. Should I have to think another way?
Post your reply..
Sandy
0 Kudos
Message 1 of 7
(3,305 Views)

This can very easily be accomplished by using a case structure to check if it's time to pause and if it is, have a piece of code which will not complete until your condition has been filled.

For example -

The real question should be what are you trying to accomplish? That should help in determining the method of the solution.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).


___________________
Try to take over the world!
0 Kudos
Message 2 of 7
(3,295 Views)

Thanks for the idea. Could solve my problem.

Sandy

0 Kudos
Message 3 of 7
(3,286 Views)
The problem is better handled with a while loop. It is very simple to specify the maximum number of iterations by putting something like a compare on the loop counter. Then inside the while loop you can put in code to generate any kind of activity you require includign pause, continue and perhaps most importantly, stop...
0 Kudos
Message 4 of 7
(3,243 Views)
On the surface, yes, but for loops have functionality that while loops do not.  You can't wire an indexing input to a while loop, and a while loop will always execute at least once, whereas a for loop may not.

Like tst said, it really depends on what Sandy is trying to accomplish...
0 Kudos
Message 5 of 7
(3,242 Views)


@Novatron wrote:
On the surface, yes, but for loops have functionality that while loops do not.  You can't wire an indexing input to a while loop, and a while loop will always execute at least once, whereas a for loop may not.

Yes, you can have indexing array inputs into a while loop, just change the input tunnel to indexing. If the array gets depleted, you'll get the default value for that data type for later iterations.
 
A FOR loop with zero iterations should be used with care to make sure you'll get the outputs you want. But yes, It is sometimes useful.
 
Tst's suggestion looks sutable to "Pause" a FOR loop (as seems to be the issue here). Stopping a FOR loop is something entirely different. 😉
 
The choice between WHILE and FOR loops depends on the knowledge of the the total number of iterations  before the loop starts. If the number is known use a FOR loop, if not use a WHILE loop. Both can be paused by the same method.
0 Kudos
Message 6 of 7
(3,238 Views)
 


altenbach wrote Yes, you can have indexing array inputs into a while loop, just change the input tunnel to indexing. If the array gets depleted, you'll get the default value for that data type for later iterations.




Sorry, I should have been more careful with my wording. What I meant was if you want your loop to run a specified number of times (random data sample for instance), but you don't know that number until runtime, then a while loop makes more work for yourself if you want to use indexing inputs. This is especially useful (to me quite often) when you want it to run the minimum number of times for more than one indexing input, as a for loop does this automatically, where you would need some extra code to use a while loop.

Message Edited by Novatron on 08-30-2005 02:34 PM

0 Kudos
Message 7 of 7
(3,233 Views)