PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Other statements used to exit from a loop
  • Example for using 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
The BREAK statement is used to exit a statement block and to resume the current process.
The BREAK statement can be used in the following types of loops:
Note: The BREAK statement cannot be used to exit from a procedure. Use the RETURN and RESULT keywords.
Versions 16 and later
Universal Windows 10 App This feature is available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This feature is available for the Windows Phone applications.
Universal Windows 10 App This feature is available for the Windows Phone applications.
Versions 17 and later
iPhone/iPad This feature is available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This feature is available for the iPhone/iPad applications.
iPhone/iPad This feature is available for the iPhone/iPad applications.
Versions 18 and later
Universal Windows 10 App This feature is available in Windows Store apps mode.
Android Widget This feature is available in Android Widget mode.
New in version 18
Universal Windows 10 App This feature is available in Windows Store apps mode.
Android Widget This feature is available in Android Widget mode.
Universal Windows 10 App This feature is available in Windows Store apps mode.
Android Widget This feature is available in Android Widget mode.
Versions 21 and later
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
New in version 21
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
Universal Windows 10 App This feature is available in Universal Windows 10 App mode.
Apple Watch This feature is available in Apple Watch mode.
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: Note: The BREAK statement cannot be used to exit from a procedure. Use the RETURN and RESULT keywords.
  • Versions 19 and later
    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.
      Versions 20 and later
      WEBDEV - Browser code The BREAK label: is now available in browser code.
      New in version 20
      WEBDEV - Browser code The BREAK label: is now available in browser code.
      WEBDEV - Browser code The BREAK label: is now available in browser code.
    New in version 19
    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.
      Versions 20 and later
      WEBDEV - Browser code The BREAK label: is now available in browser code.
      New in version 20
      WEBDEV - Browser code The BREAK label: is now available in browser code.
      WEBDEV - Browser code The BREAK label: is now available in browser code.
    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.
      Versions 20 and later
      WEBDEV - Browser code The BREAK label: is now available in browser code.
      New in version 20
      WEBDEV - Browser code The BREAK label: is now available in browser code.
      WEBDEV - Browser code The BREAK label: is now available in browser code.
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 from the loop and exit from the current process (or procedure).
  • RESULT: Return a status report to the calling process. Exit from the loop and exit from the current process (or procedure).
Close is used to exit from the loop and to close the current window.
Caution: RETURN and RESULT cannot be used in the same process.
Versions 19 and later

Example for using 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
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
New in version 19

Example for using 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
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

Example for using 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
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
Versions 19 and later

"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
New in version 19

"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

"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 required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment