Iteration/Looping (WHILE DO END)

Classic Control - Lathe Operator's Manual

The Online Interactive Operator's Manual is currently available in English only.

A PDF version of the Operator's Manual is available for download in multiple languages. Click the link below to view the Operator's Manual in your language. Click "Continue" to view the online version in English.

Get a translated PDF Download Continue

Essential to all programming languages is the ability to execute a sequence of statements a given number of times or to loop through a sequence of statements until a condition is met. Traditional G coding allows this with the use of the L address. A subroutine can be executed any number of times by using the L address.

M98 P2000 L5 ;

This is limited since you cannot terminate execution of the subroutine on condition. Macros allow flexibility with the WHILE-DO-END construct. For example:

% WHILE [] DOn ; ; ENDn ; %

This executes the statements between DOn and ENDn as long as the conditional expression evaluates to True. The brackets in the expression are necessary. If the expression evaluates to False, then the block after ENDn is executed next. WHILE can be abbreviated to WH. The DOn-ENDn portion of the statement is a matched pair. The value of n is 1-3. This means that there can be no more than three nested loops per subroutine. A nest is a loop within a loop.

Although nesting of WHILE statements can only be up to three levels, there really is no limit since each subroutine can have up to three levels of nesting. If there is a need to nest to a level greater than 3, then the segment containing the three lowest levels of nesting can be made into a subroutine thus overcoming the limitation.

If two separate WHILE loops are in a subroutine, they can use the same nesting index. For example:

% #3001=0 (WAIT 500 MILLISECONDS) ; WH [#3001 LT 500] DO1 ; END1 ; #3001=0 (WAIT 300 MILLISECONDS) ; WH [#3001 LT 300] DO1 ; END1 ; %

You can use GOTO to jump out of a region encompassed by a DO-END, but you cannot use a GOTO to jump into it. Jumping around inside a DO-END region using a GOTO is allowed.

An infinite loop can be executed by eliminating the WHILE and expression. Thus,

% DO1 ; END1 ; %

executes until the RESET key is pressed.

caution: The following code can be confusing:
% WH [#1] D01 ; END1 ; %

In this example, an alarm results indicating no Then was found; Then refers to the D01. Change D01 (zero) to DO1 (letter O).

Be aware: Many service and repair procedures should be done only by authorized personnel. The service technicians at your Haas Factory Outlet (HFO) have the training, experience, and are certified to do these tasks safely and correctly. You should not do machine repair or service procedures unless you are qualified and knowledgeable about the processes.

Danger: Some service procedures can be dangerous or life-threatening. DO NOT attempt a procedure that you do not completely understand. Contact your Haas Factory Outlet (HFO) and schedule a service technician visit if you have any doubts about doing a procedure.

Feedback