ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / Structured statements
  • Code to run
  • Exiting from a loop
  • Running the next iteration
  • Loop without end
  • External variable in a loop
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 statement block is repeated endlessly. The number of iterations in the statement block is not checked, there is no expression to evaluate.
Example
// Exit according to an IF condition
LOOP
// Read a line in the text file
ALine = fReadLine(FileNum)
 IF ALine = EOT THEN BREAK
ProcessLine(ALine)
END
// Exit according to a WHILE condition
LOOP
// Read a line in the text file
ALine = fReadLine(FileNum)
ProcessLine(ALine)
DO WHILE ALine <> EOT
// Exit according to an iteration
LOOP (10)
// Read a line in the text file
ALine = fReadLine(FileNum)
ProcessLine(ALine)
END
Syntax

Loop with exit according to an "IF" condition Hide the details

LOOP
   ...
   IF <Condition> THEN BREAK
   ...
END
<LOOP>:
Marks the beginning of the statement block.
<BREAK>:
Used to exit from the statement block.
<END>:
Marks the end of the statement block.

Loop with exit according to a "WHILE" condition Hide the details

LOOP
...
DO WHILE <Condition>
<LOOP>:
Marks the beginning of the statement block.
<DO WHILE>:
Marks the end of the statement block. Used to exit from the statement block. The lines of the loop found before this statement are run.

Loop with exit according to the number of iterations Hide the details

LOOP (<Number of iterations>)
...
END
<LOOP>:
Marks the beginning of the statement block.
<Number of Iterations>:
Number of iterations to perform. The program will exit the loop when the number of iterations is reached.
<END>:
Marks the end of the statement block.
Remarks

Code to run

The code to be executed is placed between the LOOP and END statements.

Exiting 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).
  • BREAK: Exit from the loop and run the rest of the current process.
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.

Running the next iteration

To directly run the next iteration without ending the code of the current iteration, use the CONTINUE statement:
LOOP
...
IF <Condition> THEN  CONTINUE // Go back to the LOOP keyword
...
END

Loop without end

During the compilation of the project, an endless loop (no BREAK, RETURN or RETURN) is signaled by a warning.

External variable in a loop

A variable declared by EXTERN cannot be used in a loop.
Minimum version required
  • Version 9
This page is also available for…
Comments
LOOP WITH INDIRECTION
PROCEDURE UI_EsconteMostraTodos(bEsconteMostra is boolean)

Botao,NomeMes is string = ""
NumNomeMes, Mes is int

LOOP(12)
NumNomeMes++
IF NumNomeMes = 1 THEN
NomeMes = "JAN"
ELSE IF NumNomeMes = 2 THEN
NomeMes = "FEV"
ELSE IF NumNomeMes = 3 THEN
NomeMes = "MAR"
ELSE IF NumNomeMes = 4 THEN
NomeMes = "ABR"
ELSE IF NumNomeMes = 5 THEN
NomeMes = "MAI"
ELSE IF NumNomeMes = 6 THEN
NomeMes = "JUN"
ELSE IF NumNomeMes = 7 THEN
NomeMes = "JUL"
ELSE IF NumNomeMes = 8 THEN
NomeMes = "AGO"
ELSE IF NumNomeMes = 9 THEN
NomeMes = "SET"
ELSE IF NumNomeMes = 10 THEN
NomeMes = "OUT"
ELSE IF NumNomeMes = 11 THEN
NomeMes = "NOV"
ELSE IF NumNomeMes = 12 THEN
NomeMes = "DEZ"
END
LOOP(12)
Mes ++
Botao = "BTN_"+NomeMes+"_" + NumToString(Mes,"02.00f")
IF bEsconteMostra = True
{Botao,indControl}..Visible = True
ELSE
{Botao,indControl}..Visible = False
END
END
Mes = 0
END
BOLLER
18 Apr. 2019

Last update: 05/26/2022

Send a report | Local help