Mitsubishi QD51 Programming Manual page 559

Logic controller
Hide thumbs Also See for QD51:
Table of Contents

Advertisement

11 INSTRUCTIONS AND FUNCTIONS
SWAP
Instruction
• Swaps the values of two variables.
SWAP <variable 1>,<variable 2>
Syntax
Variable 1
Variable 2
SWAP A%,B%
Examples
• The SWAP instruction exchanges the value of the variable specified in <variable 1> and
Description
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
30 INPUT "B=";B
40 PRINT "A=";A,"B=";B
50 SWAP A,B
60 PRINT "The values were swapped"
70 PRINT "A=";A,"B=";B
80 END
RUN
A=? 1
B=? 2
A= 1
B= 2
The values were swapped
A= 2
B= 1
OK
11 - 389
SWAP
• • • •
• • • •
• • • •
REMARK
See the BSWAP instruction.
Specify the variables whose values are exchanged.
Swaps the values of A% and B%.
A%
120
B%
340
:
' Inputs A
:
' Inputs B
:
' Displays the values before the swapping
:
' Swaps the values
:
' Displays the values after the swapping
MELSEC-Q
A%
340
B%
120
11 - 389

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ad51h-s3Qd51-r24A1sd51s

Table of Contents