ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / Structured statements
  • Other statements used to exit 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 a statement block and 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 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 statement block.
- Run the rest of the current process.
Remarks

Other statements used to exit 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 the loop and 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
TotalOfInvoices is currency
 
NbInvoices = 0
// Iterate over invoices starting from last invoice
HReadLast(ORDER, OrderNumber)
WHILE NOT HOut()
 
IF NbInvoices >= 10 THEN BREAK // Jump directly to the BREAK: label
// Adds the invoices
TotalOfInvoices += ORDER.TotalInclTax
NbInvoice ++
 
HReadPrevious(ORDER, OrderNumber)
BREAK:
// Exits from the loop after 10 iterations
Info("The total for the last 10 invoices is: ", TotalOfInvoices)
END

"BREAK:" statement: Case of nested loops

When there are several nested loops, you may have to exit 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

Last update: 04/17/2023

Send a report | Local help