Search code examples
loopsrpgle

How do I go to next element in a loop in RPGLE?


Let's say you have the following code:

FOR I = 1 to 10;
  // some code here
ENDFOR;

How would you skip over an element? Currently using GOTO works, but I do not like that solution. For example:

   FOR I = 1 to 10;
     IF I = 4;
C                   GOTO      NEXTONE
     ENDIF;

     // some code here

C     NEXTONE       TAG   
   ENDFOR;

Solution

  • The ITER operation transfers control from within a DO or FOR group to the ENDDO or ENDFOR statement of the group. It can be used in DO, DOU, DOUxx, DOW, DOWxx, and FOR loops to transfer control immediately to a loop's ENDDO or ENDFOR statement. It causes the next iteration of the loop to be executed immediately. ITER affects the innermost loop.

    https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/zziter.htm