ITERATE statement

The ITERATE statement can be used to force a new iteration in a loop. With this statement it’s possible to jump out earlier of a loop. Typically it will be used in a labeled LOOP.
Example:

 create procedure myproc (out var01 integer,out var02 integer)
 begin
 
   set var01 = 0;
   set var02 = 0;

   label2: LOOP
      set var01 = var01 + 1;
    
      if ( var01 > 100 or var02 > 100 ) then   
        leave label2;
      end if;

      if  var02 > 50 then
        iterate label2;
      end if;

      set var02 = var02 +1;
    end loop;

 end!


> call myproc (?,?)
> 
>  Value of output parameters
>  --------------------------
>  Parameter Name  : VAR01
>  Parameter Value : 101
> 
>  Parameter Name  : VAR02
>  Parameter Value : 51
> 
>  Return Status = 0

Link to the DB2 Information Center: DB2 9.7 DB2 10.1 DB2 10.5