LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

what diference between timed loop and while loop and for loop

If I want to count 2 second working in the loop and next then going out of the loop
I don't know which the loop  I can use


Message Edited by Jairak on 07-26-2008 03:14 PM
0 Kudos
Message 1 of 4
(2,839 Views)
Why do you need a loop to count for 2 seconds?

To learn more about LabVIEW it is recommended that you go through the tutorial(s) and look over the material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.
0 Kudos
Message 2 of 4
(2,837 Views)
Hi,
 
From the information you have provided, I don't know exactly what you are trying to do. However, if you want a loop to iterate once, wait until two seconds and then exit the loop, use the "Wait Until Next ms Multiple" function, wire in a numeric constant "2000" and wire a boolean true constant to the loop condition of the while loop to iterate once, or use a for loop with "1" wired into the loop count.
 
Perhaps you need to elaborate your question. Plus, check out the context help (press Ctrl + H) for a consice report on each of the loops.
 
Regards,
0 Kudos
Message 3 of 4
(2,820 Views)


Jairak wrote:
If I want to count 2 second working in the loop and next then going out of the loop
I don't know which the loop  I can use

If you know the time/iteration of the loop, you can easily calculate how many iterations you need until 2 seconds are up. This means you can use a FOR loop. You always use a FOR loop of you know the number of iterations before the loop starts.
 
If the time per iteration is varaible or unknown, and you cannot know how many iterations will be needed until 2 seconds are up, you need a while loop. In a while loop, you need to test yout stop condition at each iteration. In this case, you would check if 2 seconds have elapsed.
 
A timed loop is more precise at keeping a defined time per iteration and can even tell you if an iteration finishes late do to too much code. It is more useful in conditions where the time per iteration needs to be very precise.
 
Overall, you should probably start with a few tutorials and look at the help pages of the various loops to get familiar with the differences. Do you have experiences in any other programming languages?.
 
 
You could also try to describe im much more details what you are actually trying to do and we might have more specific suggestions. 🙂
0 Kudos
Message 4 of 4
(2,810 Views)