Goto Statement; Return Statement - Siemens S7-1200 System Manual

Hide thumbs Also See for S7-1200:
Table of Contents
Basic instructions
7.8 Program control operations
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;
7.8.9.9

GOTO statement

Table 7- 126 GOTO statement
SCL
GOTO JumpLabel;
Statement;
... ;
JumpLabel: Statement;
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;
7.8.9.10

RETURN statement

Table 7- 127 RETURN instruction
SCL
RETURN;
Example of a RETURN instruction:
IF "Error" <> 0 THEN
RETURN;
END_IF;
274
Description
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.
Description
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).
S7-1200 Programmable controller
System Manual, 03/2014, A5E02486680-AG
Table of Contents
loading

Table of Contents