End of program, Program structure instructions, Do/while structure – 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 164

Advertising
background image

142

IQ Programming Structure • Program Structure Instructions

Publication 1398-PM601A-EN-P — October 2000

TUTORIAL

X1:;Xkey programs

... statements;Any IQ Basic instructions

XEND

Main Body

... statements;Any IQ Basic instructions

;End of main body of program

Subroutines

SUB SUB1

... statements;Any IQ Basic instructions

RET

End of program

END

The Title section of the program consists of a single TITLE instruction, which designates a name up to
8 characters long. The program title is displayed in the directory. The TITLE statement is not required,
but a warning will be generated if a program without a title is compiled.

The Header section of the program contains compiler options statements, assignments of names to vari-
ables used in the program, plus scanned events and operator terminal Xkey routines. If none of these are
used in a program, the header section is not required.

The Main Body of the program contains the main part of the program, which can include all motion and
math statements, labels, I/O commands, and subroutine calls.

Subroutines are routines that are called from the body of the program. When a subroutine is called, pro-
gram execution is transferred to the subroutine until a RETURN statement occurs. Then, program exe-
cution returns to the body of the program following the CALL statement.

The END statement signifies the end of the program.

Comments are allowed in any section of the program and are preceded by a semicolon. They may occur
on the same line as an instruction, or on a line that contains only the comment. Any text following a
semicolon on a line will be ignored by the compiler.

Program Structure Instructions

Program Structure instructions are used to control the course of the program within the main body,
header, and subroutine portions of application programs and Fkey programs. The DO/WHILE, WHILE,
IF, and ON instructions are used to create conditional execution of instructions. Subroutines are used to
simplify and better organize your application program. The WAIT instruction is used to suspend the
execution of the application program.

DO/WHILE Structure

This instruction is used to execute a block of code one time and then continue executing that block until
a condition is satisfied. The difference between the DO/WHILE instruction and the WHILE instruction
is that the DO/WHILE instruction tests the condition after the block is executed so the conditional state-
ments are always executed at least one time. The syntax for the DO/WHILE instruction is:

DO

{

conditional statements

Advertising