The Start Loop and End Loop commands are used to create loops, which are blocks of commands that are executed a specified number of times. The repetition count can either be a constant value, or one computed from an expression based on signal values and other data.
These commands must be entered in matched pairs, one End Loop for every Start Loop.
Each loop begins with a Start Loop command. The Valuefield for this command specifies the number of times the loop will be repeated:
When the script is run, the loop counter will be shown updating in real time in the Value cell of the Start Loop command; it decrements from the start value down to 1 as the loop proceeds. This progression may or may not be visible, depending on how quickly the loop executes.
Note: After selecting the Start Loop command, Vehicle Spy will display it in the script as Start a loop. These are equivalent.
The End Loop command marks the end of the loop. It has no parameters.
Note: After selecting the End Loop command, Vehicle Spy will display it in the script as End the last loop. These are equivalent.
Here are two examples showing typical uses of loops.
The example in Figure 1 shows a simple script that transmits a message exactly 7 times each time it runs.
Figure 2 shows a script that waits for the receipt of a message calledCAN Control Message 1. This message contains a signal, Number of Transmissions, which dictates how often the loop runs, and thus how often CAN Message A is transmitted.