Siemens SINUMERIK Check Structures and Loops: IF, LOOP, FOR, WHILE, REPEAT, CASE and GOTO (840D sl / 828D)

4 August 2026

Mentor CNC Editör Ekibi

Check Structures and Loops on Siemens SINUMERIK

The control processes NC blocks as standard in the programmed sequence. There are two ways to vary that sequence: check structures (IF, ELSE, ENDIF, LOOP, FOR, WHILE, REPEAT) and program jumps and branches (GOTOS, GOTOB, GOTOF, GOTO, GOTOC, CASE). This page covers both, the difference between them, and when to use which.

In practice this means: instead of writing the same hole forty times you build a loop; you write one program that machines differently depending on part size; you prevent drilling during block search; you stop the program with an alarm when a probe measurement is out of tolerance. All of it is done with check structures.

Who is this page for? CNC programmers starting with parametric programming, technicians who want to write their own cycles, anyone moving from Fanuc macro B (WHILE DO / GOTO / IF) to Siemens, and everyone who builds their own probing routines.

The rules first: the limits of check structures

The manual issues a warning before it explains anything else. Programs written without knowing it fail on the machine with alarms that look unrelated:

Programming error (the manual’s own notice) Check structures may only be inserted in the statement section of a program. Definitions in the program header may not be executed conditionally or repeatedly. It is not permissible to superimpose macros on keywords for check structures or on jump targets. No such check is made when the macro is defined — so the error surfaces at runtime, not at definition time.

Supplementary conditions

RuleWhat it means on the machine
The check structure cannot be used program-wideA check structure cannot start in the main program and end in a subprogram; every level must close within itself
A nesting depth of up to 16 check structures can be set up on each subprogram levelDeeper nesting requires an additional subprogram level
Blocks with check structure elements cannot be suppressed (skip levels)Writing /1 IF ... has no effect
Jump markers (labels) are not permitted in blocks with check structure elementsLABEL: WHILE ... is invalid
Check structures are processed interpretively; when a loop end is detected, a search is made for the loop beginningFor this reason the block structure of a program is not checked completely in interpreter mode — an unbalanced ENDIF/ENDWHILE is not caught immediately
It is not generally advisable to use a mixture of check structures and program branchesDo not interleave the two in the same program section
Correct nesting can be checked when cycles are preprocessedIf you write your own cycles, use that check

What the display shows while a loop runs

If only selected blocks are executed within a program loop, the current block display shows the last main run block before the program loop. So that the processed blocks are also visible — for diagnostic purposes, for example — the decoding single block SBL2 must be activated.

This is the real cause of “the program is stuck” While the loop runs, the block number on the screen does not change and the operator assumes the program has hung. In fact the loop is running. Activate SBL2 and the blocks appear one by one.

IF, ELSE, ENDIF — conditional statement and branch

  • Conditional statement: the program block between IF and ENDIF is executed only when the condition is satisfied.
  • Branch: with IF – block_1 – ELSE – block_2 – ENDIF, one of two program blocks is always executed: block_1 if the condition is satisfied, block_2 if it is not.
; Conditional statement IF <condition> Program block ; executed when condition == TRUE ENDIF; Branch IF <condition> Program block_1 ; executed when condition == TRUE ELSE Program block_2 ; executed when condition == FALSE ENDIF
KeywordMeaning
IFIntroduces the conditional statement or branch
ELSEIntroduces the alternative program block
ENDIFMarks the end of the conditional statement or branch
<condition>Logical expression that is evaluated as TRUE or FALSE

The manual’s tool change subprogram example

This example is worth studying because it solves a real production problem: in program test mode and in real execution, the “current tool” has to be read from different places.

PROC L6 ; Tool change routine N500 DEF INT TNR_AKTUELL ; Variable for active T number N510 DEF INT TNR_VORWAHL ; Variable for preselected T number N520 STOPRE N530 IF $P_ISTEST ; In the program test mode … N540 TNR_AKTUELL = $P_TOOLNO ; … the “current” tool is read from the program context N550 ELSE ; Otherwise … N560 TNR_AKTUELL = $TC_MPP6[9998,1] ; … the tool of the spindle is read out N570 ENDIF N580 GETSELT(TNR_VORWAHL) ; Read the T number of the preselected tool in the spindle N590 IF TNR_AKTUELL <> TNR_VORWAHL ; If the preselected tool is still not the current tool … N600 G0 G40 G60 G90 SUPA X450 Y300 Z300 D0 ; … approach tool change position … N610 M206 ; … and execute a tool change N620 ENDIF N630 M17
Three lessons from this example 1. The move to the tool change position uses SUPA, so it is unaffected by any zero offset or frame. 2. The same line carries D0: tool compensation is deselected before approaching the tool change point. 3. STOPRE comes before the read operation — reading a system variable requires a preprocessing stop.

LOOP and ENDLOOP — the endless loop

Endless loops are used in endless programs. At the end of the loop there is always a branch back to the beginning.

LOOPENDLOOP
KeywordMeaning
LOOPInitiates the endless loop
ENDLOOPMarks the end of the loop and results in a return jump to the beginning of the loop

The manual’s example is the most sensible use of an endless loop — waiting for the operator:

LOOP MSG (“no tool cutting edge active”) M0 STOPRE ENDLOOP

The message appears, M0 stops the program, and when the operator corrects the situation and presses NC Start the loop returns to the beginning — and stops again if the situation has not been fixed.

Getting out of an endless loop If there is no jump command between LOOP and ENDLOOP, the loop never ends on its own. As the 2010 Turkish source puts it, the program runs until RESET is pressed or the power is switched off. So an endless loop should either be a deliberate wait construct or contain an exit condition.

FOR … TO … and ENDFOR — the count loop

The count loop is used if an operation must be repeated with a fixed number of runs.

FOR <variable> = <initial value> TO <end value> … ENDFOR
ElementMeaning
FORInitiates the count loop
ENDFORMarks the end of the loop and results in a return jump to the beginning of the loop, as long as the end value of the count has still not been reached
<variable>Count variable, incremented from the initial to the end value and increased by the value “1” at each run. Type: INT or REAL. Note: the REAL type is used if R parameters are programmed for a count loop; if the count variable is of the REAL type, its value is rounded to an integer.
<initial value>Initial value of the count. Condition: the start value must be lower than the end value.
<end value>End value of the count

Example 1 — INTEGER variable and R parameter as count variable

DEF INT iVARIABLE1 R10=R12-R20*R1 R11=6 FOR iVARIABLE1 = R10 TO R11 ; count variable = INTEGER variable R20=R21*R22+R33 ENDFOR M30R11=6 FOR R10=R12-R20*R1 TO R11 ; count variable = R parameter (real variable) R20=R21*R22+R33 ENDFOR M30

Example 2 — production of a fixed quantity of parts

DEF INT WKPCCOUNT ; defines type INT variable named “WKPCCOUNT” FOR WKPCCOUNT = 0 TO 100 ; initiates the count loop; increments from 0 to 100 G01 … ENDFOR ; end of count loop M30
The step is always 1 The SINUMERIK count loop has no step parameter; the variable is increased by one at each run. If you need a step of two, either add a second variable inside the loop or switch to a WHILE loop.

WHILE and ENDWHILE — condition at the start of the loop

For a WHILE loop, the condition is at the beginning of the loop. The WHILE loop is executed as long as the condition is fulfilled. If the condition is not fulfilled at the outset, the loop does not run at all.

WHILE <condition> … ENDWHILE
KeywordMeaning
WHILEInitiates the program loop
ENDWHILEMarks the end of the loop and results in a return jump to the beginning of the loop
<condition>The condition must be fulfilled so that the WHILE loop is executed

The manual’s example performs stepped plunging based on the actual axis position:

WHILE $AA_IW[DRILL_AXIS] > -10 ; Condition: the actual WCS setpoint for the drilling axis must be greater than -10 G1 G91 F250 AX[DRILL_AXIS] = -1 ENDWHILE

$AA_IW[...] is the axis setpoint in the workpiece coordinate system; each pass plunges 1 mm incrementally and the loop ends when the axis reaches −10.

REPEAT and UNTIL — condition at the end of the loop

For a REPEAT loop the condition is at the end of the loop. The REPEAT loop is executed once and repeated continuously until the condition is fulfilled.

REPEATUNTIL <condition>
KeywordMeaning
REPEATInitiates the program loop
UNTILMarks the end of the loop and results in a return jump to the beginning of the loop
<condition>The condition that must be fulfilled so that the REPEAT loop is no longer executed
A technical error found in the source document The 2010 Turkish source states for the REPEAT loop: “Functionally it is identical to the WHILE loop. The only difference is that in the WHILE loop the condition is at the start of the loop and in the REPEAT loop the condition is at the end of the loop.” That statement is incomplete and misleading. There are two further differences, and both invert program behaviour: The sense of the condition is inverted. In WHILE the condition must be fulfilled for the loop to run. In UNTIL the condition must be fulfilled for the loop to stop running. Writing the same condition into both structures produces opposite results. REPEAT always runs at least once. WHILE never runs if the condition is false at the outset; the REPEAT body is processed once in any case. The definitions given above are taken from the Job Planning manual, 01/2015 (6FC5398-2BP40-5BA2), and those are the definitions to work from.

Which loop should you use?

SituationCorrect structure
The number of repetitions is known in advance (40 holes, 100 parts)FOR ... TO ... ENDFOR
The number is unknown and the condition must be checked first (it may never run)WHILE ... ENDWHILE
The body must run at least once, then the condition is checkedREPEAT ... UNTIL
Operator intervention is required; the program must not continue on its ownLOOP ... ENDLOOP
One of two alternativesIF ... ELSE ... ENDIF
More than two branches, selected by an integer valueCASE ... OF ... DEFAULT

Nested check structures — the manual’s example

This example combines three structures and solves a real safety problem: no drilling must take place during block search.

LOOP IF NOT $P_SEARCH ; If no block search G1 G90 X0 Z10 F1000 WHILE $AA_IM[X] <= 100 ; WHILE (setpoint X axis <= 100) G1 G91 X10 F500 ; Drilling pattern Z-5 F100 Z5 ENDWHILE ELSE ; ELSE block search MSG(“No drilling during block search”) ENDIF $A_OUT[1] = 1 ; Next drilling plate G4 F2 ENDLOOP M30

Reading the structure: the outer LOOP keeps working plate after plate; IF NOT $P_SEARCH ensures drilling happens only in normal execution; the inner WHILE machines the hole pattern until the X axis reaches 100; during block search only a message is displayed.

Why this matters During block search the control “calculates” the program but must not cut. If the $P_SEARCH system variable is not checked, outputs and motions can be triggered during the search. Anyone writing their own cycles needs this pattern.

Program jumps: GOTOS, GOTOB, GOTOF, GOTO, GOTOC

GOTOS — return jump to the start of the program

GOTOS is used to jump back to the beginning of a main program or subprogram in order to repeat the program. Machine data can be used to set that for every return jump:

  • The program runtime is set to “0”.
  • Workpiece counting is incremented by the value “1”.
NC/PLC interface signal DB21, to DBX384.0 (control program branching)Meaning
0No return jump to the beginning of the program. Program execution is resumed with the next part program block after GOTOS.
1Return jump to the beginning of the program. The part program is repeated.
Three critical side effects of GOTOS 1. GOTOS internally initiates a STOPRE (pre-processing stop). 2. For a subprogram with data definitions (LUD variables), the jump goes to the first program block after the definition section, i.e. data definitions are not executed again. This is why the defined variables retain the value reached in the GOTOS block and are not reset to the standard values programmed in the definition section. 3. GOTOS is not available in synchronized actions and technology cycles.

GOTOB, GOTOF, GOTO, GOTOC — jumping to a label

Jump markers (labels) are set in a program and can be jumped to from another location within the same program. Program execution is resumed with the statement that immediately follows the target marker.

GOTOB <jump target> IF <jump condition> = TRUE GOTOB <jump target> GOTOF <jump target> IF <jump condition> = TRUE GOTOF <jump target> GOTO <jump target> IF <jump condition> = TRUE GOTO <jump target> GOTOC <jump target> IF <jump condition> = TRUE GOTOC <jump target>
CommandMeaning
GOTOBJump statement with jump target towards the beginning of the program
GOTOFJump statement with jump target towards the end of the program
GOTOJump statement with jump target search: the search is first made in the direction of the end of the program, then in the direction of the beginning
GOTOCSame effect as GOTO, except that alarm 14080 “Jump designation not found” is suppressed. Program execution is not interrupted if the search fails; it continues with the line following the GOTOC command.
Possible jump targetsDescription
<jump marker>A label set in the program with a user-defined name: <jump marker>:
<block number>Main block or sub-block number (e.g. 200, N300)
STRING type variableVariable jump target; the variable stands for a jump marker or a block number

Rules for naming jump markers

  • Jump markers are always located at the beginning of a block. If a program number exists, the jump marker is located immediately after the block number.
  • Number of characters: minimum 2, maximum 32.
  • Permissible characters: letters, numbers, underscores.
  • The first two characters must be letters or underscores.
  • The name of the jump marker is followed by a colon (“:”).

Supplementary conditions

  • The jump target can only be a block with a jump marker or block number located within the program.
  • A jump statement without a jump condition must be programmed in a separate block. This restriction does not apply to jump statements with jump conditions — in that case several jump statements can be formulated in one block.
  • For programs with jump statements without jump conditions, the end of program M2/M30 does not necessarily have to be at the end of the program.

Example — jump with jump condition

N40 R1=30 R2=60 R3=10 R4=11 R5=50 R6=20 ; Assignment of initial values N41 LA1: G0 X=R2*COS(R1)+R5 Y=R2*SIN(R1)+R6 ; Jump marker LA1 set N42 R1=R1+R3 R4=R4-1 N43 IF R4>0 GOTOB LA1 ; If the condition is fulfilled, jump towards the ; beginning of the program to jump marker LA1 N44 M30 ; End of program
A second error found in the source document The same example appears in the 2010 Turkish source with corrupted block numbers: N150 MA1:N160N170N150 again → N190. The same block number (N150) is used twice and N180 is skipped. The version above is the correctly numbered example from the 01/2015 Job Planning manual. Duplicate block numbers break block search and jump behaviour.

Example — indirect jump to a block number

N5 R10=100 N10 GOTOF “N”<<R10 ; Jump to the block whose block number is located in R10 … N90 … N100 … ; Jump target N110 …

Example — jump to a variable jump target

DEF STRING[20] DESTINATION DESTINATION = “Marker2” GOTOF DESTINATION ; Jump towards the end of the program to the ; variable jump target DESTINATION Marker1: T=”Drill1″ … Marker2: T=”Drill2″ ; Jump target

These two patterns let one program handle different tool or process scenarios: the target name is held in a variable and the decision is made inside the program.

CASE … OF … DEFAULT — multi-way branch

The CASE function provides the possibility of checking the actual value (type: INT) of a variable or an arithmetic function and, depending on the result, jumping to different positions in the program.

CASE(<expression>) OF <constant_1> GOTOF <jump target_1> <constant_2> GOTOF <jump target_2> … DEFAULT GOTOF <jump target_n>
ElementMeaning
CASEJump statement
<expression>Variable or arithmetic function
OFKeyword to formulate conditional program branches
<constant_1>, <constant_2>Specified constant values for the variable or arithmetic function. Type: INT
DEFAULTDetermines the jump target for the cases where the variable does not assume any of the specified constant values. If DEFAULT is not programmed, the block following the CASE statement is the jump target.
GOTOFJump statement towards the end of the program. Instead of GOTOF, all other GOTO commands can be programmed.

The manual’s example

N20 DEF INT VAR1 VAR2 VAR3 N30 CASE(VAR1+VAR2-VAR3) OF 7 GOTOF Label_1 9 GOTOF Label_2 DEFAULT GOTOF Label_3 N40 Label_1: G0 X1 Y1 N50 Label_2: G0 X2 Y2 N60 Label_3: G0 X3 Y3
  1. If VAR1+VAR2−VAR3 = 7, jump to the block with the jump marker “Label_1” (→ N40).
  2. If VAR1+VAR2−VAR3 = 9, jump to the block with the jump marker “Label_2” (→ N50).
  3. If the result is neither 7 nor 9, jump to the block with the jump marker “Label_3” (→ N60).
Where CASE pays off Calling different machining routines by part type, clamping station, measurement result class or operator selection. Nested IF statements can do the same job, but CASE is more readable and faster for integer comparisons.

Program section repetition: REPEAT, REPEATB, ENDLABEL, P

Program section repetition allows you to repeat existing program sections within a program in any order. The program lines or sections to be repeated are identified by jump markers (labels).

Careful: there are two different REPEATs The REPEAT in this section is not the REPEAT ... UNTIL loop from the previous section. This REPEAT is a program section repetition and takes a repetition count through the P address. The same keyword serving two purposes is one of the most frequently confused points in Siemens programming.

Four syntax forms

1. Repeat an individual program line

<jump marker>: … … REPEATB <jump marker> P=<n>

2. Repeat the section between the jump marker and the REPEAT statement

<jump marker>: … … REPEAT <jump marker> P=<n>

3. Repeat the section between two jump markers

<start jump marker>: … … <end jump marker>: … … REPEAT <start jump marker> <end jump marker> P=<n>

4. Repeat the section between a jump marker and ENDLABEL

<jump marker>: … … ENDLABEL: … … REPEAT <jump marker> P=<n>
ElementMeaning
REPEATBCommand for repeating a program line
REPEATCommand for repeating a program section
ENDLABELKeyword marking the end of a program section to be repeated. ENDLABEL can be used more than once in the program. If the line with ENDLABEL contains further operations, these are executed again on each repetition.
P=<n>Number of program section repetitions (type INT). After the last repetition, the program is resumed at the line following the REPEAT/REPEATB line. In the absence of a number being specified for P=<n>, the program section is repeated just once.

Search direction of the jump marker

The program line identified by the jump marker can appear before or after the REPEAT/REPEATB statement. The search initially commences toward the start of the program; if the jump marker is not found in this direction, the search continues toward the end of the program.

Exception If the program section between the jump marker and the REPEAT statement is to be repeated (form 2 above), the line identified by the jump marker has to appear before the REPEAT statement, since in this case the search runs only toward the beginning of the program.

Also: if the line with the jump marker contains further operations, these are executed again on each repetition.

Example 1 — repeat an individual program line

N10 POSITION1: X10 Y20 N20 POSITION2: CYCLE(0,,9,8) ; Position cycle N30 … N40 REPEATB POSITION1 P=5 ; Execute BLOCK N10 five times N50 REPEATB POSITION2 ; Execute block N20 once N60 … N70 M30

Example 2 — section between jump marker and REPEAT statement

N5 R10=15 N10 Begin: R10=R10+1 ; Width N20 Z=10-R10 N30 G1 X=R10 F200 N40 Y=R10 N50 X=-R10 N60 Y=-R10 N70 Z=10+R10 N80 REPEAT BEGIN P=4 ; Execute section from N10 to N70 four times N90 Z10 N100 M30

Example 3 — section between two jump markers

N5 R10=15 N10 Begin: R10=R10+1 ; Width N20 Z=10-R10 N30 G1 X=R10 F200 N40 Y=R10 N50 X=-R10 N60 Y=-R10 N70 END: Z=10 N80 Z10 N90 CYCLE(10,20,30) N100 REPEAT BEGIN END P=3 ; Execute section from N10 to N70 three times N110 Z10 N120 M30

Example 4 — machining the same drill positions with different technologies

This is the most powerful use of program section repetition: the drill positions are written once and then recalled for centering, drilling and tapping.

N10 CENTER DRILL() ; Load centering drill N20 POS_1: ; Drilling positions 1 N30 X1 Y1 N40 X2 N50 Y2 N60 X3 Y3 N70 ENDLABEL: N80 POS_2: ; Drilling positions 2 N90 X10 Y5 N100 X9 Y-5 N110 X3 Y3 N120 ENDLABEL: N130 DRILL() ; Change drill and drilling cycle N140 THREAD(6) ; Load tap M6 and threading cycle N150 REPEAT POS_1 ; Repeat section once from POS_1 up to ENDLABEL N160 DRILL() ; Change drill and drilling cycle N170 THREAD(8) ; Load tap M8 and threading cycle N180 REPEAT POS_2 ; Repeat section once from POS_2 up to ENDLABEL N190 M30

Further information and limits

  • Program section repetitions can be nested. Each call uses a subprogram level.
  • If M17 or RET is programmed during processing of a program section repetition, the repetition is canceled. The program is resumed at the block following the REPEAT line.
  • In the actual program display, the program section repetition is displayed as a separate subprogram level.
  • If the level is canceled during the program section repetition, the program resumes at the point after the program section repetition call.
  • It is not possible to nest the REPEAT statement with the two jump markers in parentheses. If the start jump marker appears before the REPEAT statement and the end jump marker is not reached before the REPEAT statement, the section between the start jump marker and the REPEAT statement will be repeated. The same restriction applies to the jump marker + ENDLABEL form.
  • Check structures and program section repetitions can be used in combination, but there should be no overlap between the two. A program section repetition should appear within a check structure branch, or a check structure should appear within a program section repetition.
  • If jumps and program section repetitions are mixed, the blocks are executed purely sequentially. For example, if a jump is performed from a program section repetition, processing continues until the programmed end of the program section is found.
  • The REPEAT statement should appear after the traversing block.

Check structure or jump — which one?

The manual answers this directly:

Runtime response (the manual’s wording) In interpreter mode (active as standard), it is possible to shorten program processing times more effectively by using program branches than can be obtained with check structures. There is no difference between program branches and check structures in precompiled cycles.
Check structures (IF, WHILE, FOR…)Jumps (GOTOB, GOTOF, CASE)
ReadabilityHigh — the structure is visibleLow — you have to trace labels
Speed in interpreter modeSlowerFaster
Speed in precompiled cyclesNo differenceNo difference
Nesting limit16 per subprogram levelNo structural limit, but complexity grows
Block suppression (skip)Not possiblePossible
LabelsNot permitted in the same blockRequired

Practical advice: prefer check structures for readability and maintainability. If you write cycles and they will be precompiled, there is no difference anyway. Switch to jumps only where a very long, very frequently repeated loop makes interpreter-mode runtime a real problem. Do not mix the two in the same section — the manual explicitly advises against it.

The most common mistakes on the shop floor

  1. Treating the WHILE and UNTIL conditions as equivalent. In WHILE the condition must hold “to run”; in UNTIL it must hold “to stop running”. The same condition in both gives opposite results.
  2. Putting variable definitions inside a loop. Check structures work only in the statement section; header definitions cannot be executed conditionally or repeatedly.
  3. Writing a label in a check structure block. Jump markers are not permitted in blocks with check structure elements.
  4. Trying to suppress a check structure line with a skip level. Those blocks cannot be suppressed.
  5. Leaving an unbalanced ENDIF / ENDWHILE / ENDFOR. Because the block structure is not fully checked in interpreter mode, the error only appears at runtime.
  6. Exceeding the nesting limit of 16. Up to 16 check structures per subprogram level.
  7. Not knowing that GOTOS triggers a STOPRE. This can explain unexpected dwell in a program running in continuous-path mode.
  8. Expecting variables to be reset after GOTOS. LUD variables retain their values; the definition section is not executed again.
  9. Confusing the program section repetition REPEAT with the REPEAT loop. One takes a count with P=<n>, the other ends with UNTIL.
  10. Writing REPEAT without a P value. Without P the section is repeated just once — many users assume “not at all” or “forever”.
  11. Overlapping a check structure with a section repetition. One has to be entirely inside the other.
  12. Omitting the block-search check ($P_SEARCH). Motions and outputs can be triggered during block search.

Frequently asked questions

What is the equivalent of Fanuc macro B’s WHILE [condition] DO1 … END1?

WHILE <condition> ... ENDWHILE. SINUMERIK has no DO/END numbers; nested structures match by keyword.

Can I use a step of 2 in a FOR loop?

No. The count variable is increased by 1 at each run. If you need a different step, use WHILE and write the increment yourself.

Can I use an R parameter as the count variable?

Yes. The variable is then of the REAL type and, as the manual states, its value is rounded to an integer.

What happens if the initial value is higher than the end value?

The manual sets the condition clearly: the start value must be lower than the end value. FOR is not the right structure for the reverse case.

How do I stop a program from looping forever?

Put an exit condition (IF + GOTOF) inside LOOP–ENDLOOP, or convert the structure to WHILE. Otherwise, as the 2010 source notes, the program only stops on RESET or power-off.

When is GOTOC used?

In optional program sections where the jump target sometimes exists and sometimes does not. If the target is not found, alarm 14080 is suppressed and the program continues with the next line.

What happens if I omit DEFAULT in a CASE statement?

If the variable equals none of the specified constants, the block following the CASE statement becomes the jump target.

What is the difference between REPEAT and calling a subprogram?

REPEAT needs no separate file; it repeats a section within the same program. However, each REPEAT call uses a subprogram level and appears as a separate subprogram level in the actual program display.

Why does the block number on the screen not change inside a loop?

Because the current block display shows the last main run block before the loop. To see the processed blocks, activate the decoding single block SBL2.

Mentor CNC note: Check structures and jumps decide which motion happens when; a wrong condition can send the tool somewhere it should never go. Every new loop or branch should first be verified in graphics/simulation, then run with the workpiece removed, in single block and at reduced feed override. Endless loops and conditional tool change routines in particular must be supervised on their first run. The syntax, value ranges and system variables on this page are based on the Siemens sources listed below; they can differ with the control version and the machine manufacturer’s configuration. The machine manufacturer’s documentation always takes precedence. This page is for training purposes and does not replace the official manuals.

Sources

  • Siemens AG — SINUMERIK Advanced CNC Operation & Programming (Turkish edition), 05/2010: Section 4.8 Indirect programming (conditional jump, CASE branch), Section 4.9 Loops (endless loop LOOP–ENDLOOP, IF–ELSE–ENDIF, count loop FOR–ENDFOR, WHILE–ENDWHILE, REPEAT–UNTIL)
  • Siemens AG — SINUMERIK 840D sl / 828D Job Planning, Programming Manual, 01/2015, document no. 6FC5398-2BP40-5BA2: Section 2.10 Program jumps and branches (2.10.1 GOTOS, 2.10.2 GOTOB/GOTOF/GOTO/GOTOC, 2.10.3 CASE…OF…DEFAULT), Section 2.11 Repeat program section (REPEAT, REPEATB, ENDLABEL, P), Section 2.12 Check structures (2.12.1 IF/ELSE/ENDIF, 2.12.2 LOOP/ENDLOOP, 2.12.3 FOR/ENDFOR, 2.12.4 WHILE/ENDWHILE, 2.12.5 REPEAT/UNTIL, 2.12.6 program example with nested check structures)