Mitsubishi Electronics FX2N ユーザーズマニュアル

ページ / 382
FX Series Programmable Controlers
Applied Instructions 5
5-13
5.1.7
FOR, NEXT
(FNC 08, 09)
Operation:
T h e   F O R   a n d   N E X T   i n s t r u c t i o n s   a l l o w   t h e
specification of an area of program, i.e. the program
enclosed by the instructions, which is to be repeated
S number of times.
Points to note:
a) The FOR instruction operates in a 16 bit mode hence, the value of the operand S may be
within the range of 1 to 32,767. If a number between the range -32,768 and 0 (zero) is
specified it is automatically replaced by the value 1, i.e. the FOR-NEXT loop would execute
once.
b) The NEXT instruction has NO operand.
c) The FOR-NEXT instructions must be programmed as a pair e.g. for every FOR instruction
there MUST be an associated NEXT instruction. The same applies to the NEXT
instructions, there MUST be an associated FOR instruction. The FOR-NEXT instructions
must also be programmed in the correct order. This means that programming a loop as a
NEXT-FOR (the paired NEXT instruction proceeds the associated FOR instruction) is NOT
allowed.
Inserting an FEND instruction between the FOR-NEXT instructions, i.e. FOR-FEND- NEXT,
is NOT allowed. This would have the same effect as programming a FOR without a NEXT
instruction, followed by the FEND instruction and a loop with a NEXT and no associated
FOR instruction.
d) A FOR-NEXT loop operates for its set number of times before the main program is allowed
to finish the current program scan.
e) When using FOR-NEXT loops care should be taken not the exceed the PLC’s watchdog
timer setting. The use of the WDT instruction and/or increasing the watchdog timer value is
recommended.
Mnemonic
Function 
Operands
Program steps
S
FOR
FNC 08
(Start of a
FOR-NEXT
loop)
Identifies the start
position and the
number of
repeats for the
loop
K, H,
KnX, KnY, KnM, KnS,
T, C, D, V, Z
FOR:
3 step
NEXT
FNC 09
(End of a
FOR-NEXT
loop)
Identifies the end
position for the
loop
N/A
Note:
The FOR-NEXT loop can be nested for 5 lev-
els,
i.e. 5 FOR-NEXT loops are programmed within 
each other.
NEXT:
1 step
FX
0(S)
FX
0N
FX FX
(2C)
FX
2N(C)
FX
(2C)
FX
FX
2N(C)
FX
0N
FX
0(s)
PULSE-P
FX
(2C)
FX
FX
2N(C)
FX
0N
FX
0(s)
16 BIT OPERATION
FX
FX
0N
FX
0(s)
FX
(2C)
FX
2N(C)
32 BIT OPERATION
FOR K1X0
NEXT
[ S ]