3. Statements : OpenROAD Language Statements : While Statement : Examples—While Statement
 
Share this page                  
Examples—While Statement
Repeat a prompt five times or until a valid answer is given:
answer = prompt 'Please answer Y or N';
requests = 0;
while(lowercase(left(answer,1)) != 'y' and
     lowercase(left(answer,1)) != 'n') and
     requests < 5 do
          answer = prompt 'Please answer Y or N:';
          requests = requests + 1;
endwhile;
Use the while statement to handle deadlock:
tries = 1;
while tries <= 10 do
          /* insert statement to try to insert
          ** into database
          */
     if iierrornumber = 0 then
          /* Success */
          commit work;
          message 'Insert successful';
          tries = 10;
     else
          message 'Insert failed due to db error';
          rollback work;
          /* Try again on deadlock */
          /* OpenSQL Serialization Failure */
          if iierrornumber = -49900 then
               tries = tries + 1;
          else
               endloop;
          endif;
     endif;
endwhile;