Break

This instruction is used to exit loops in scripts.

Syntax

Break INTEGER_EXPRESSIONBreak

Examples

# This calculation loop continues as long as the expected precision is not reached, or if the condition# OUT_OF_RANGE becomes true (CHECK_DATA must returns 0 or 1 only)RepeatOUT_OF_RANGE=Func CHECK_DATA(DATA_ARRAY)Break OUT_OF_RANGEPRECISION=Func STEP_N(DATA_ARRAY)Until PRECISION<EXPECTED# This calculation loop continues as long as the expected precision is not reached, or if the condition# OUT_OF_RANGE becomes true (CHECK_DATA returns 0 if OK and any other error code if not ok)PRECISION=1While PRECISION>=EXPECTEDOUT_OF_RANGE=Func CHECK_DATA(DATA_ARRAY)Break (OUT_OF_RANGE<>0)PRECISION=Func STEP_N(DATA_ARRAY)Wend# Multi-level database request# RESULT gives the final result of a computation that uses values stored in a database table# Stops if CODE is found equal to an EXIT_CODE value, if SUBCODE is found equal to EXIT_SUBCODE value,#if ID is found equal to EXIT_ID value, or if AMOUNT is equal to EXIT_AMOUNT# Skips to the next (CODE,ID) group if CATEGORY is found equal to a SKIP_CATEGORY value, Local Decimal RESULTLocal File MYTABLE [MYT] Order By Key READ_KEY=[MYT]CODE;[MYT]SUBCODE;[MYT]CATEGORY;[MYT]IDFor [MYT]READ_KEY(1) : # Loop on distinct CODE valuesBreak [MYT]CODE=EXIT_CODE: # Exit from the loopFor [MYT]READ_KEY(2) : # Loop on distinct SUBCODE values for a given CODE valueBreak 2*([MYT]SUBCODE=EXIT_SUBCODE) : # Exit from the 2 nested loops if condition is trueFor [MYT]READ_KEY(3): # Loop on distinct CATEGORY values for a given (CODE,SUBCODE) pairBreak CATEGORY=SKIP_CATEGORY : # Exit from a unique level to go to the next (CODE,SUBCODE) pairFor [MYT]READ_KEY(4) : # Loop on distinct ID for a given (CODE,SUBCODE,CATEGORY) setIf [MYT]ID=EXIT_IDBreak 4: # Exit from all the nested loopsEndifFor [MYT]READ_KEY : # Loop on all the records for a given (CODE,SUBCODE,CATEGORY,ID) setBreak 5*(AMOUNT=EXIT_AMOUT) : # Exit from all loops if condition is trueRESULT=Func COMPUTATION(RESULT,[MYT]AMOUNT) : # Performs the computationNextNextNext# This is the point where the execution continues if we skip the categoryNextNext# Test a condition for values found in a 2 dimensions matrix# The loop is interrupted if the value is found.For I=1 to dim(MATRIX,1)For J=1 to dim(MATRIX,2)If MATRIX(I,J)=VECTOR(I+J)Break 2EndifNext JNext I

Description and comments

The instruction Break can be used for any For / Next loop, While / Wend loop, and Repeat / Until loops.

The exit is done at the end of the corresponding loop.

See also

For, To, Step, Next, While, Wend, Repeat, Until.