Table Of Contents

Adjusting the Execution Speed of a Loop

Last Modified: November 1, 2016

By default, each loop iteration executes as quickly as possible based on the code inside the loop. However, you might want to control the rate at which a loop executes in order to specify a fixed time interval for each iteration, reduce the speed at which an indicator changes value, or conserve processing resources.

What to Use

What to Do

Create the following diagram to adjust the execution speed of a loop.

Customize the gray sections for your unique programming goals.

Place the code you want to repeat on the subdiagram of a While Loop or For Loop.

To specify the amount of time to wait between loop iterations, wire the desired time duration to the input of the Wait node. The Wait node waits until the value of the operating system's counter increases by an amount equal to the input you specify.

The total running time of the loop is equal to the greater of the time it takes to run the code inside the loop and the wait time you specify.

Pressing the stop button does not interrupt the Wait node. For example, if the user presses the stop button in the middle of a loop iteration, the While Loop stops only after the specified wait period has elapsed and the code inside the loop has finished executing.

Troubleshooting

If a loop does not execute at the desired rate, verify that you have specified the input of the Wait node correctly. Consider the following common mistakes:

  • If you are converting from another unit of time, verify that your conversion calculation is correct.
  • If your code takes longer than expected to execute, note that the total running time of the loop is equal to the greater of the time it takes to run the code inside the loop and the wait time you specify.

Recently Viewed Topics