Basic instructions
7.8 Program control operations
S7-1200 Programmable controller
274 System Manual, 03/2014, A5E02486680-AG
Use the EXIT statement within a loop. In nested loops, the EXIT statement returns the
processing to the next higher nesting level.
FOR i := 0 TO 10 DO
CASE value[i, 0] OF
1..10: value [i, 1]:="A";
11..40: value [i, 1]:="B";
41..100: value [i, 1]:="C";
ELSE
EXIT;
END_CASE;
END_FOR;
Table 7- 126 GOTO statement
Statement;
... ;
JumpLabel: Statement;
The GOTO statement skips over statements by jumping to a label in the same
block.
The jump label ("JumpLabel") and the
GOTO statement must be in the same block.
The name of a jump label can only be assigned once within a block. Each jump
label can be the target of several GOTO statements.
It is not possible to jump to a loop section (FOR, WHILE or REPEAT). It is possible to jump
from within a loop.
In the following example: Depending on the value of the "Tag_value" operand, the execution
of the program resumes at the point defined by the corresponding jump label. If "Tag_value"
equals 2, the program execution resumes at the jump label "MyLabel2" and skips
"MyLabel1".
CASE "Tag_value" OF
1 : GOTO MyLabel1;
2 : GOTO MyLabel2;
ELSE GOTO MyLabel3;
END_CASE;
MyLabel1: "Tag_1" := 1;
MyLabel2: "Tag_2" := 1;
MyLabel3: "Tag_4" := 1;
Table 7- 127 RETURN instruction
The Return instruction exits the code block being executed without conditions. Program
execution returns to the calling block or to the operating system (when exiting an OB).
Example of a RETURN instruction:
IF "Error" <> 0 THEN
RETURN;
END_IF;