Repeat, Loop, and Subroutine Opcodes
- Updated2026-01-30
- 4 minute(s) read
The repeat, loop, and subroutine opcodes are used to iterate over vectors, manage loop counts and early exits, and call and return from subroutines. These opcodes help in structuring reusable pattern blocks.
Conceptual Overview
In a pattern, repeat and loop opcodes control iteration, and call and return control subroutine execution. Use them to repeat vectors, define loops, exit loops early, and execute reusable subroutines. Subroutines are analogous to function calls.
The optional ! character inverts conditions.
Syntax Reference
| Syntax | Description |
|---|---|
| repeat(numeric) | Executes the current vector the specified number of times. |
| repeat(register) | Reads the repeat count from the specified pattern sequencer register and executes the current vector that many times. Pattern sequencer registers pass numeric values between the pattern sequencer and a run‑time test program. |
| set_loop(numeric) | Sets the number of loop iterations for the next loop block. After calling set_loop, label the first and last vectors of the loop and use end_loop(label). |
| set_loop(register) | Reads the loop count from the specified register. Allows runtime control of
loop iterations. After calling set_loop, label the first and last vectors of the loop and use end_loop(label). |
| end_loop(label) | Marks the last vector in the loop. Executes the vector and compares completed iteration to the count set by set_loop. If iterations remain, jumps to the label and repeats. Otherwise, the opcode pops the loop stack and continues. |
| exit_loop(label) | Exits the loop immediately, pops the loop stack, and jumps to the specified label. |
| exit_loop_if([!]failed, label) | Executes the current vector and conditionally exits the loop if any comparison failed. |
| exit_loop_if([!]seqflag, label) | Exit the loop if you set the specified sequencer flag. |
| exit_loop_if([!]matched, label) | Exits the loop if the vector executed exactly 80 cycles prior matched. |
| exit_loop_if([!]trigger, label) | Exit the loop if the system asserts the specified trigger. |
| call(label) | Jumps to the subroutine specified by the label. Executes until a return opcode, then resumes after the call. Subroutine calls can nest up to eight levels deep. |
| return | Executes the current vector and then jumps to the vector that follows the vector with the corresponding call opcode. |
Parameter Descriptions
Valid range: 1–65535.
Valid range: reg0–reg15.
Evaluation Differences
The system evaluates the matched parameter and the !failed parameter differently. Similarly, !matched parameter and the failed parameter have distinct evaluations. For more details, see the descriptions of the matched parameter and failed parameter.
Special Considerations
- match opcode
- matched parameter of the jump_if opcode or the exit_loop_if opcode in burst patterns
- failed parameter of the jump_if opcode or the exit_loop_if opcode in burst patterns
Synchronization Requirements for Comparison Results
- niDigital Enable Match Fail Combination VI
- EnableMatchFailCombination .NET method
- niDigital_EnableMatchFailCombination C function
Early Loop Exit Using exit_loop_if(seqflag0, ...)
// Set the number of loop iterations for the looping operation. set_loop(100) sample_timeset X; // Set the label for the looping operation. loop: sample_timeset X; // Exit the loop prematurely if seqflag0 is set to true. exit_loop_if(seqflag0, exit) sample_timeset X; end_loop(loop) sample_timeset X; exit: halt sample_timeset X;
Calling a Subroutine and Returning to the Next Vector
// This vector executes first. call(sub1) sample_timeset 0 L; // This vector executes after the subroutine returns. halt sample_timeset 1 H; ... sub1: sample_timeset 0 L; // Return to the vector following the call. return sample_timeset 0 L;