Skip to content

BREAK

Abort Loop Control

This directive causes transfer of program execution to the statement after a NEXT or WEND.

BREAK

This directive is generally available starting with release level 8.8.0.

For nested loops, this directive will transfer program execution to the statement after the innermost NEXT or WEND directive.

If a BREAK is executed without a FOR/NEXT or WHILE/WEND loop on the stack, an ERR=28 results.

If this directive is used in Thoroughbred Basic Console Mode, an ERR=45 results.

01000 FOR MON = 1 TO 12;
IF SALES[MON] = 0
BREAK
FI;
TOTSALES = TOTSALES + SALES[MON];
NEXT MON;
PRINT TOTSALES;

prints the cumulative total of the SALES array, aborting the execution of the FOR/NEXT loop if one of the array elements is set to 0.

01000 MON = 1;
WHILE MON <= 12;
IF SALES[MON] = 0
BREAK
FI;
TOTSALES = TOTSALES + SALES[MON];
WEND;
PRINT TOTSALES;

prints the cumulative total of the SALES array, aborting the execution of the WHILE/WEND loop if one of the array elements is set to 0.

01000 FOR I=10 TO 5000;
FOR J=2 TO I-1
IF MOD(I,J)=0
BREAK
ELSE
IF I=J+1
PRINT I," ",
FI
FI;
NEXT J;
NEXT I

prints all prime numbers from 10 to 5000.

CONTINUE, FOR/NEXT, and WHILE/WEND directives

From the Thoroughbred Basic Language Reference, Volume I: A–E, version 8.9.1. Open this page in the PDF