LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do I count while loops

Solved!
Go to solution

Im following an example to count the number of loops my program has done. However it doesnt seem to work. Ive attached a DBL indicator to the i in the while loop of the block diagram. I have attached the program below.

 

Regards, Sam 

 

 

0 Kudos
Message 1 of 6
(3,280 Views)

Hi Sam,

why did you start a new thread if this is your solution

http://forums.ni.com/ni/board/message?board.id=170&thread.id=430766&jump=true?

 

Mike

 

Message 2 of 6
(3,274 Views)

 


Hi Sam,

why did you start a new thread if this is your solution

http://forums.ni.com/ni/board/message?board.id=170&thread.id=430766&jump=true?

 

Mike

 


 

 

Mike,

 

Maybe this is another while loop and not the same used in that thread and he just want to get a confirmation on whether it will work the same way........ :smileyvery-happy:

Message 3 of 6
(3,267 Views)
Solution
Accepted by topic author ssteel

The while loop counter starts at zero, so if you want to know the numebr of loop iterations, you will need to add 1 to the loop counter.

 

Your loop will also only run one time if the STOP button is not pressed since you have the while loop condifitional terminal set to continue if true.  If you press the button before you run the code, it will only run twice, because you have the boolean set to latch, so when the loop reads the boolean, it will switch back to false and stop the loop.

 

I think you want to change the conditional terminal back to stop if true.

Message 4 of 6
(3,259 Views)

thanks, worked like a dream

 

Sam 

0 Kudos
Message 5 of 6
(3,256 Views)

Hi Sam,

 

Just some additional observations/tips on your code...

 

1. I notice that you have a standard stop button going into a "run if true" stop condition of the while loop. In this cercumstance it is common to have the stop condition set as "stop if true". You can change this by right clicking the stop terminal and enabling the "stop if true" property. Obviously, it somewhat depends on your design preferences.

 

2. If you have any issues with the application, perhaps you notice that it is taking over your processor resources, you should add some execution timing into the while loop. You will find the timing functions in the block diagrams functions palette (programming > timing). The Wait (or "wait until next ms") functions will provide your application with "down time", which means that the processor can execute other tasks.

 

3. To elaborate what MikeS81 correctly stated, insert an incriment before the numeric indicator as shown below to get the actual number of cycles (i.e. the count terminal of the "while" and "for" loops are 0 indexed). Also note that I have changed the representation of the count to interger (blue). You do not need floating point precision when displaying the incriment count, as a while loop can only execute a "whole number" of times.

 

incriment count.JPG

 

I hope this has been useful to you Sam. Thanks for your post, Rich R

Message Edited by RER on 08-11-2009 11:55 AM
Rich Roberts
Senior Marketing Engineer, National Instruments
Connect on LinkedIn: https://www.linkedin.com/in/richard-roberts-4176a27b/
0 Kudos
Message 6 of 6
(3,199 Views)