06-30-2015 01:09 PM
@Scaz wrote:
Ok, thank you. I understand that part. My question is, how do I continuously run this loop N number of times, resetting it back to 0 after each N times. I need to repeatly send data over a serial connection that sets certain fields to certain values depending on this N value. Each iteration is one message and after N number of times, it resets and repeats the process. Hopefully this clarifies.
A For loop inside of a While loop.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
06-30-2015 01:21 PM
You can also maintain the iteration value in a shift register and reset it back to zero. Or you can look at the i value of the for loop, do a Quotient Remainder with the N value, and use the remainder output. That will cause the output to roll back to 0 whenever i becomes equal to N or a multiple of N.
06-30-2015 01:25 PM
If your number of cases is defined at edit time, you could use an enum to name your states and then just increment the enum (stored in a shift register). The enum will roll over when you increment from the last defined value. The bonus to this method is that your case structure has a text to the selection instead of just a number.