While structure, Subroutines, While structure subroutines – Rockwell Automation 1398-PDM-xxx IQ Master Version 3.2.4 for IA-2000 and IQ-5000 Positioning Drive Modules, IQ-55 User Manual

Page 165: Tutorial

Advertising
background image

IQ Programming Structure • Program Structure Instructions

143

Publication 1398-PM601A-EN-P — October 2000

TUTORIAL

} WHILE condition

Refer to Part 5

Language Reference for more detailed information. The following flowchart and code

segment illustrate the use of the DO/WHILE instruction.

WHILE Structure

This instruction is used if you want a block of code to execute while a condition is true. The difference
between the DO/WHILE instruction and the WHILE instruction is the WHILE instruction tests the con-
dition before any of the conditional statements are executed. If the condition is false when first tested,
the conditional statements are never executed. The syntax for the WHILE instruction is:

WHILE condition

{

conditional statements

}

Refer to Part 5

Language Reference for more detailed information. The following flowchart and code

segment illustrate the use of the WHILE instruction.

Subroutines

A subroutine is a group of IQ Basic instructions that is located at the end of the main body of the pro-
gram. It is marked by the SUB instruction at the top and a RETURN instruction at the end. The subrou-
tine is executed by using a CALL instruction in the main body of the program.

Subroutines are used if there is a procedure that needs to be done in several places in the program.
Rather than repeat those instructions at each location, a CALL to a subroutine that contains those
instructions may be used.

statements

DO

{

MOVD = 3

O1 = ON

DELAY = 2

} WHILE (I2 = ON)

statements

statements

WHILE (I2 = ON)

{

MOVD = 3

O1 = ON

DELAY 2

}

statements

Start

Move Distance 3 inches

Output 1 ON

Delay 2 seconds

End

Is Input 2 ON

Yes

No

Start

Move Distance 3 inches

Output 1 ON

Delay 2 seconds

End

Is Input 2 ON

Yes

No

Advertising