Program loops
FOR loop
Application
You can use a FOR loop to program simple program-section repeats.
Related topics
- Subprograms and program-section repeats
Description of function
A program loop consists of a header and footer and all the defined NC blocks between them. You use the FOR and END FOR NC functions to define the header and footer.
The control indents the NC blocks between the header and footer.
The control executes the NC program as follows:
- The control reads the header with the counting variable, the target value, and the increment, if given.
- The control writes the starting value to the counting variable.
Since the value of the counting variable is less than or equal to the target value, the control executes the loop content.
- The control reads the footer and returns to the header.
- The control changes the value of the counting variable by the increment.
Since the value of the counting variable is less than or equal to the target value, the control executes the loop content.
- The control reads the footer and returns to the header.
- The control changes the value of the counting variable by the increment.
Since the value of the counting variable is greater than the target value, the control skips the loop content and jumps directly to the footer.
- The control ends the program loop and continues the NC program.
Input
NC programs contained in this User's Manual are suggestions for solutions. The NC programs or individual NC blocks must be adapted before being used on a machine.
Change the following contents as needed:
- Tools
- Cutting parameters
- Feed rates
- Clearance height or safe position
- Machine-specific positions (e.g., with M91)
- Paths of program calls
Some NC programs depend on the machine kinematics. Adapt these NC programs to your machine kinematics before the first test run.
In addition, test the NC programs using the simulation before the actual program run.
With a program test you determine whether the NC program can be used with the available software options, the active machine kinematics and the current machine configuration.
11 FOR Q50 = 4 TO 10 STEP 2 | ; Header of the FOR loop |
* - ... | ; Content is executed until the value of Q50 is greater than 10 |
21 END FOR | ; Footer of the FOR loop |
To navigate to this function:
Insert NC function All functions FN Program section repeat FOR header and footer
The NC function includes the following syntax elements:
Syntax element | Meaning |
---|---|
FOR | Syntax initiator of a FOR loop |
Q50 | Counting variable With each repetition of the program loop the control checks the value of this variable. If the value is less than the target value, the control changes this value by the increment. |
= 4 | Start value At the start of the program loop, the control assigns this value to the counting variable once. Only integers smaller than the target value are possible. Number or numerical parameter |
TO 10 | Target value The control repeats the program loop until the value of the counting variable is greater than the target value. Only integers are possible Number or numerical parameter |
STEP 2 | Increment Only integers are possible If you don't define an increment, the control uses the value 1. Number or numerical parameter Optional syntax element |
You can use the Insert NC function window to insert a combination of header and footer or both lines.
Notes
- If you program numerical parameters in the header, then you must define the variables before the program loop.
- Do not assign a new value to the counting variable within the program loop, since that could lead to an infinite loop.
- If you program jump commands (e.g., using FN 9) within program loops, the control will display an error message.
WHILE loop
Application
You can use a WHILE loop to program simple program-section repeats with various conditions. The conditions can contain numerical or alpha-numerical values.
Related topics
- Subprograms and program-section repeats
Description of function
A program loop consists of a header and footer and all the defined NC blocks between them. You use the WHILE and END WHILE NC functions to define the header and footer.
The control indents the NC blocks between the header and footer.
The control executes the NC program as follows:
- The control assigns the value 2 to the variable Q10 and then reads the header with the condition.
- The control checks whether the condition is fulfilled.
Since the condition is fulfilled, the control executes the loop content.
Within the program loop the control increments the value of the variable Q10.
- The control reads the footer and returns to the header.
- The control checks whether the condition is fulfilled.
Since the condition is fulfilled, the control executes the loop content.
Within the program loop the control increments the value of the variable Q10.
- The control reads the footer and returns to the header.
- The control checks whether the condition is fulfilled.
Since the condition is no longer fulfilled, the control skips the loop content and jumps directly to the footer.
- The control ends the program loop and continues the NC program.
You can use numerical values when programming the following conditions:
Condition | Meaning | ||
---|---|---|---|
a | == | b | a equal to b |
a | != | b | a not equal to b |
a | < | b | a less than b |
a | > | b | a greater than b |
a | <= | b | a less than or equal to b |
a | >= | b | a greater than or equal to b |
You can use alpha-numerical values when programming the following conditions:
Condition | Meaning | ||
---|---|---|---|
a | == | b | a equal to b |
a | != | b | a not equal to b |
a | IN | b | a contained in b The control checks whether the content to the left of IN is contained in the same sequence in the content to the right. The control also takes capitalization into account. |
Input
NC programs contained in this User's Manual are suggestions for solutions. The NC programs or individual NC blocks must be adapted before being used on a machine.
Change the following contents as needed:
- Tools
- Cutting parameters
- Feed rates
- Clearance height or safe position
- Machine-specific positions (e.g., with M91)
- Paths of program calls
Some NC programs depend on the machine kinematics. Adapt these NC programs to your machine kinematics before the first test run.
In addition, test the NC programs using the simulation before the actual program run.
With a program test you determine whether the NC program can be used with the available software options, the active machine kinematics and the current machine configuration.
11 Q50 = +5 | ; Define Q50 with the value 5 |
12 Q60 = +10 | ; Define Q60 with the value 10 |
13 WHILE Q50 <= Q60 | ; Header of the WHILE loop |
14 Q50 = Q50 + +1 | ; Increment Q50 by the value 1 |
* - ... | ; Content will be executed until the value in Q50 is greater than the value in Q60 |
21 END WHILE | ; Footer of the WHILE loop |
To navigate to this function:
Insert NC function All functions FN Program section repeat WHILE header and footer
The NC function includes the following syntax elements:
Syntax element | Meaning |
---|---|
WHILE | Syntax initiator of a WHILE loop |
Q50 <= Q60 | Condition Number, text, or variable |
You can use the Insert NC function window to insert a combination of header and footer or both lines.
Notes
- If you program numerical parameters in the header, then you must define the variables before the program loop.
- You can use a WHILE loop to achieve the functionality of a FOR loop.. To do so, define a calculation step within the program loop in order to increment or decrement a value.
- If you program jump commands (e.g., using FN 9) within program loops, the control will display an error message.
- Please note that the control considers digits from the tenth decimal place onward to be identical. This means, for example, that calculation results differing only after the ninth decimal place will be considered to have the same value.