query_script_break
break: quit loop execution
SYNOPSIS
while (expression) { if (expression) break; }
DESCRIPTION
break is a QueryScript statement which, when invoked, aborts execution of current loop.
break is typically used in an if-else statement, but does not necessarily has to.
The break statements quits iteration of the closest wrapping loop, but not any above it.
The following loops are all affected by break: while, loop-while, foreach.
EXAMPLES
Break on condition:
set @x := 7; while (@x > 0) { set @x := @x - 1; if (@x = 3) break; } select @x; +------+ | @x | +------+ | 3 | +------+
An immediate break:
set @x := 7; while (true) { set @x := @x - 1; break; } select @x; +------+ | @x | +------+ | 6 | +------+
Break from inner loop; outer loop unaffected
set @x := 3; while (@x > 0) { set @x := @x - 1; set @y := 3; while (@y > 0) { set @y := @y -1; if (@y < @x) break; select @x, @y; } } +------+------+ | @x | @y | +------+------+ | 2 | 2 | +------+------+ +------+------+ | @x | @y | +------+------+ | 1 | 2 | +------+------+ +------+------+ | @x | @y | +------+------+ | 1 | 1 | +------+------+ +------+------+ | @x | @y | +------+------+ | 0 | 2 | +------+------+ +------+------+ | @x | @y | +------+------+ | 0 | 1 | +------+------+ +------+------+ | @x | @y | +------+------+ | 0 | 0 | +------+------+