11 - 389 11 - 389
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
SWAP
Instruction
SWAP
• Swaps the values of two variables.
SWAP <variable 1>,<variable 2>
Syntax
Variable 1
• • • •
Specify the variables whose values are exchanged.
Variable 2
• • • •
Examples
SWAP A%,B%
• • • •
Swaps the values of A% and B%.
120
340
A%
B%
120
340
A%
B%
Description
• The SWAP instruction exchanges the value of the variable specified in <variable 1> and
the value of the variable specified in <variable 2>.
• Any types of variables can be specified in <variable> (integer, single-precision, double-
precision, or character string). However, a "Type mismatch" error occurs if the types of two
variables do not match.
Program Example
10 ' This program swaps the data in the variables A and B
20 INPUT "A=";A
:
' Inputs A
30 INPUT "B=";B
:
' Inputs B
40 PRINT "A=";A,"B=";B
:
' Displays the values before the swapping
50 SWAP A,B
:
' Swaps the values
60 PRINT "The values were swapped"
70 PRINT "A=";A,"B=";B
:
' Displays the values after the swapping
80 END
RUN
A=? 1
B=? 2
A= 1 B= 2
The values were swapped
A= 2 B= 1
OK
REMARK
See the BSWAP instruction.