Progress
Programming
Handbook


Looping

Looping, or iteration, is one of the automatic processing services that Progress provides for blocks. REPEAT blocks and FOR EACH blocks iterate automatically and you can force a DO block to iterate by using a DO WHILE, or a DO variable = expression1 TO expression2 [BY k]. The following code fragments show iterations using these block statements:

p-bkchp.p
/* This REPEAT block loops through its statements until the user  
   presses the END-ERROR (F4) key.                              */ 
REPEAT: 
  PROMPT-FOR customer.cust-num. 
  FIND customer USING cust-num. 
  DISPLAY customer WITH 2 COLUMNS. 
END. 

p-bkchp2.p
/* This FOR EACH block reads the records from the customer 
   table one at a time, processing the statements in the  
   block for each of those records.                       */ 
FOR EACH customer: 
  DISPLAY customer WITH 2 COLUMNS. 
END. 

REPEAT and FOR EACH blocks iterate automatically. You can make a DO block iterate by using the WHILE option or the TO option in the DO block header:

p-bkchp3.p
/* This block loops through its statements for the first 5 customers. */ 
DEFINE VARIABLE i AS INTEGER. 
DO i = 1 TO 5: 
  FIND NEXT customer. 
  DISPLAY customer WITH 2 COLUMNS. 
END. 


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095