Chapter 5 Instruction Specifications

Syntax of FOR to NEXT

1] A NEXT instruction with the same code number as the code number n of the FOR instruction is required after the FOR instruction.

FOR 1 (WR0010)

5] It is possible to escape from a FOR to NEXT loop using a jump instruction.

FOR 1 (WM001)

The FOR 1 to NEXT 1 loop is

 

Program

NEXT 2

Program

Program

NEXT 5

Program

FOR 5 (WM04F)

Program

NEXT undefined error The NEXT instruction with respect to the FOR instruction does not exist within the user program.

FOR undefined error

The FOR instruction does not exist before the NEXT instruction.

NEXT to FOR error

The NEXT instruction exists before the FOR instruction.

 

escaped when X00000 turns on

CJMP 10 (X00000)

before the loop has been repeated

NEXT 1

for the set number of repeats

 

(content of WM001).

LBL10

 

6] FOR to NEXT may be nested up to 5 levels. When a subroutine is included, the FOR to NEXT within the subroutine is counted.

FOR 1(WR0001)

FOR 2(WR0002)

FOR 3(WR0003)

FOR 4(WR0004)

FOR 5(WR0005)

2] An overlap of FOR and NEXT instructions with the same code number n is not allowed.

FOR 6(WR0006)

• Nesting overflow error

 

NEXT 6

 

FOR 3 (WR10)

Program

NEXT 3

Program

FOR 3

Program

NEXT 3

FOR duplicate-definition error A FOR instruction with the same code number n is programmed.

NEXT duplicate-definition error A NEXT instruction with the same code number n is programmed.

Note: FOR and NEXT duplicate- definition errors will occur during operation pre-processing.

NEXT 5

NEXT 4

NEXT 3

NEXT 2

NEXT 1

7] Do not include a startup condition between FOR and

NEXT. If a startup condition is required, create a circuit as shown below:

X00000

JMP 1

3] FOR and NEXT must be within the same area.

 

Program head

Normal scan

FOR 1(WR0001)

 

FOR 2(WR0002)

 

END

Subroutine

SB1

NEXT 2

SB1

FOR 3(WR0003)

 

RTS

 

SB2

Subroutine

NEXT 3

SB2

FOR 4(WR0004)

 

RTS

 

INT0

Interrupt scan

NEXT 4

 

NEXT 1

 

RT1

4] Use FOR to NEXT as a nest.

[Operation description]

FOR 1(WM001)

Program C

When X00000 is off, program C is repeatedly executed for the number of WM 1 times.

NEXT 1

When X00000 is on, program C is not executed since a jump is performed from JMP 1 to LBL 1.

LBL 1

8] The number of repeats may be modified within the program.

WR0010=20

FOR 1(WR0010)

Program A

R005

WR0010=1

NEXT1

FOR 1 (WM001)

FOR 1(WM001) to NEXT 1 will execute normally.

Program B

The content of WR0010 decrements by 1 and a jump is performed to FOR 1 (WR0010).

Program FOR 2 (WM002)

Program NEXT 1

FOR3 Program

NEXT 2

Nesting error When WM002=0

Since FOR 1(WM001) to NEXT 1 is prioritized, jump will not be performed over NEXT 1 from FOR 2 to NEXT 2. At this time, NEXT 2 generates a FOR 2 undefined error.

When WM002 ≠ 0

FOR 2 will not do anything. Therefore, NEXT 2 will generate a FOR 2 undefined error.

When R005 is off

Program B is executed after program A is repeated 20 times.

When R005 is on

The repeat counter WR0010 changes to 1, and since the NEXT 1 processing subtracts 1 from it, the content of WR0010 becomes 0. Therefore, the repeating of program A is terminated and program B is execute

5-108

Page 158
Image 158
Hitachi NJI-350B manual Syntax of for to Next, 108