drop function if exists repeatfunction // create function repeatfunction() returns int begin declare l_repeat_count int default 0; rep1: repeat set l_repeat_count = l_repeat_count + 1; if l_repeat_count = 5 then leave rep1; end if; until l_repeat_count = 10 end repeat rep1; return l_repeat_count; end //