views:

57

answers:

1

Inside MySQL I have written a Procedure where I want to run a loop like this:

While (Cond) Do
  ...(Body1)
  ...
  If (Condition2)
    continue ;

  ...(Body2)
  ...
end while ;

Under the while loop I want the full body to run in case where Condition2 is not met (ie Body1 and Body2).

Currently, when Condition 2 is met, it just executes Body1 and then continues(Check Cond in While and Continue looping.)

Can someone help with the proper syntax to perform the above?

+1  A: 
BEGIN
    WHILE cond1 DO
        CALL body1;
        IF (NOT cond2) THEN
            CALL body2;
        END IF;
    END WHILE;
END;
Quassnoi