PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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 statement block.
<BREAK>:
Used to exit from the statement block.
<END>:
Marks the end of statement block.

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

LOOP
...
DO WHILE <Condition>
<LOOP>:
Marks the beginning of statement block.
<DO WHILE>:
Marks the end of 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 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 statement block.
Remarks

Code to run

The code to run is found between the LOOP and END statements.

Exiting 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).
  • 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 RESULT 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 RESULT) 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
Video Loop
https://youtu.be/J4q8rvjRQVA

https://windevdesenvolvimento.blogspot.com/2019/03/dicas-2054-windev-comandos-50-loop.html

// BTN_LOOP
nCONTADOR is int=0
LOOP (5)
nCONTADOR++
Trace(nCONTADOR)
END
Info("FINALIZADO LOOP")
amarildo
24 Mar. 2019