PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Other statements used to exit from a loop
  • Usage example of the "BREAK:" label
  • "BREAK:" statement: Case of nested loops
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
The keyword BREAK can correspond:
  • to the BREAK statement:
    The BREAK statement is used to exit from a statement block and to run the rest of the current process.
    The BREAK statement can be used in the following types of loops: Remark: The BREAK statement cannot be used to exit from a procedure. Use the RETURN and RESULT keywords.
  • to the BREAK: label:
    The "BREAK:" label is used to declare a code in a loop.
    • This code will be run when exitingfrom the loop with a "BREAK" statement.
    • This code will never be run for each iteration of the loop.
Syntax

BREAK statement used in a FOR statement

FOR <Control variable> = <Initial value> TO <Final value> [STEP <x>]
  ...
  IF <Condition> THEN BREAK
  ...
END
<Rest of process>

BREAK statement used in a FOR EACH statement

FOR EACH <File> ON <Key item>
  ...
  IF <Condition> THEN BREAK
  ...
END
<Rest of process>

BREAK statement used in a LOOP statement

LOOP
  ...
  IF <Condition> THEN BREAK
  ...
END
<Rest of process>

BREAK statement used in a WHILE statement

WHILE <Condition>
  ...
  IF <Condition> THEN BREAK
  ...
END
<Rest of process>
The following operations are performed if <Condition> is True:
- Exit from the statement block.
- Run the rest of the current process.
Remarks

Other statements used to exit from a loop

Several statements are available:
  • RETURN: Exit the loop and the current process (or procedure).
  • RETURN: Return a status report to the calling process. Exit the loop and the current process (or procedure).
Close is used to exit from the loop and to close the current window.
Caution: RETURN and RETURN cannot be used in the same process.

Usage example of the "BREAK:" label

In this example, the total representing the sum of the last 10 invoices is displayed.
NbInvoices is int
TotInv is currency
 
NbInvoices = 0
// Iterate over invoices starting from last invoice
HReadLast(Invoice, InvNum)
WHILE NOT HOut()
NbInvoice ++
IF NbInvoices >= 10 THEN BREAK // Jump directly to the BREAK: label
  // Adds the invoices
TotInv += Invoice.Amount
 
BREAK:
// Exits from the loop after 10 iterations
Info("The total for the last 10 invoices is: ", InvTtl)
HReadPrevious(Invoice, InvNum)
END

"BREAK:" statement: Case of nested loops

When having several nested loops, you may have to exit from an iteration in order to go back to the previous level or even to a higher level.
To do so, the BREAK statement accepts a parameter indicating the number of levels to move up for the exit. The syntax is as follows:
BREAK(<Number of levels>)
where <Number of levels> is an integer between 1 and N, N representing the number of nested levels for the loop.
For example:
x, y, z are int

FOR x = 1 TO 15 // Loop 1
FOR y = 1 TO 25 // Loop 2
FOR z = 1 TO 50 // Loop 3
IF <My condition is checked> THEN
BREAK(2) // Exits from loop 3 and loop 2
// and goes to the next iteration in loop 1
END
END
END
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment