This command repeatedly executes the specified formula until it encounters a command that will exit the loop.
Note: The cell references inside the text for a LOOP command are not updated the way a cell reference usually is (for example, when a column is added to the template.) That is because the text for the loop is just text.
Syntax
LOOP "formula_string"
The "formula_string" must be a valid template formula.
It may include multiple commands that are separated by a colon (:).
It must include one of the following commands to exit the loop:
Return value
This command does not return a value.
Notes
When the same formula must be executed multiple times in succession, the LOOP command will perform much faster than the GOTO [this cell] command (which must exit and re-enter the cell on each iteration). The reason for the difference is that GainSeeker automatically performs some extra functions every time it exits a cell; the GOTO [this cell] command must exit and re-enter the cell on each iteration, whereas the LOOP command does not leave the cell.
Sometimes GainSeeker may appear to be unresponsive if you execute the LOOP command with a very large number of iterations. If this is the case, you can include the command DOEVENTS in the "formula_string" so that the SPC Data Entry module will re-paint the screen and be responsive to keystrokes (such as CTRL + ALT + SHIFT + D to launch the DEBUG window) and mouse clicks while the LOOP command is being executed.
When the DEBUG window is launched within a loop, it will only display the "formula_string" for the LOOP command, and you can exit the loop by selecting the Exit template check box and then clicking Close. GainSeeker will then display the DEBUG window with the entire formula (including the LOOP command) for the current cell.
If a syntax error occurs, this command will set the value of a variable named MySVar "Loop_Error" to equal the error message, and then it will exit the loop.
Examples
NVar 1 = 0:
Loop "
NVar 1 = NVar 1 + 1 :
Display_Part NVar 1 :
If NVar 1 > 9999, LOOP_BREAK
"
This formula increments the variable NVar 1 from 0 to 10000.
The Display_Part command is used to display the current value of NVar 1 in the Part Number box on the data entry screen; however, without using a DOEVENTS command to force GainSeeker to re-paint the screen this probably will not occur until NVar 1 reaches 10001 and GainSeeker exits the loop.
NVar 1 = 0:
Loop "
NVar 1 = NVar 1 + 1 :
Display_Part NVar 1 :
DOEVENTS :
If NVar 1 > 9999, LOOP_BREAK
"
This formula increments the variable NVar 1 from 0 to 10000.
The Display_Part command is used to display the current value of NVar 1 in the Part Number box on the data entry screen, and the DOEVENTS command forces GainSeeker to re-paint the screen before proceeding with command execution.
NVar 1 = 0:
Loop "
NVar 1 = NVar 1 + 1 :
If NVar 1 % 100 = 0, Display_Part NVar 1 + DOEVENTS :
If NVar 1 > 9999, LOOP_BREAK
"
This formula increments the variable NVar 1 from 0 to 10000.
Every time NVar 1 reaches a multiple of 100, the Display_Part command is used to display the current value of NVar 1 in the Part Number box on the data entry screen, and the DOEVENTS command forces GainSeeker to re-paint the screen before proceeding with command execution. Reducing the screen re-paint to every 100 iterations of the loop will make this formula perform faster than the previous formula (which forces a screen re-paint on each iteration).
NVar 1 = 0:
SVar 1 = 'C1' :
Loop "
NVar 1 = NVar 1 + 1 :
If NVar 1 % 100 = 0, Display_Part NVar 1 + DOEVENTS :
If NVar 1 = 9876, SVar 1 = 'J1' :
If NVar 1 > 9999, GOTO [SVar 1]
"
This formula increments the variable NVar 1 from 0 to 10000.
Every time NVar 1 reaches a multiple of 100, the Display_Part command is used to display the current value of NVar 1 in the Part Number box on the data entry screen, and the DOEVENTS command forces GainSeeker to re-paint the screen before proceeding with command execution. Reducing the screen re-paint to every 100 iterations of the loop will make this formula perform faster than the previous formula (which forces a screen re-paint on each iteration).
When NVar 1 reaches the value of 9876, the value of SVar 1 changes to 'J1'. This means that when NVar 1 reaches 10000, the template will execute a "GOTO [J1]" command.