BREAK statement

The XCSB break statement is used to immediately exit a loop or select statement.

Use of BREAK in FOR statement

The following example uses a break statement to terminate a for loop when x is equal to 15.

x = 0

for j=1 while j<=10 step j=j+1 do

	if x == 15 then
		break
	endif

	x = x + j

done
It is equivalent to:
x = 0

for j=1 while j<=10 step j=j+1 do

	if x == 15 then
		goto lab_end
	endif

	x = x + j

done

lab_end:

Use of BREAK in WHILE statement

The break statement also has the same effect when used in a while loop.

When the break statement is used in a loop that is nested inside another loop, the action of the break statement is to immediately exit the innermost loop statement that encompasses it.

e.g.

x = 0

for j=1 while j<=10 step j=j+1 do

	for k=1 while k<=10 step k=k+1 do

		if x == 15 then
			break
		endif

		x = x + k

	done

	w = w + x

done
This is equivalent to
x = 0

for j=1 while j<=10 step j=j+1 do

	for k=1 while k<=10 step k=k+1 do

		if x == 15 then
			goto lab_001
		endif

		x = x + k

	done

lab_001:

	w = w + x

done

Use of BREAK in SELECT statement

The following example shows the use of break statements to terminate case statement lists within a select statement

select x of

case 1

	a = b
	break

case 2

	a = b + c
	break

case 3

	a = b - c
	break

end_select
It is equivalent to:
select x of

case 1

	a = b
	goto lab_end

case 2

	a = b + c
	goto lab_end

case 3

	a = b - c
	goto lab_end

end_select

lab_end: