ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / Structured statements
  • Code to run
  • Exiting from a WHILE loop
  • Loop without end
  • Running the next iteration
  • Composite condition
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
In a WHILE statement, the expression is evaluated at the beginning of the statement block.
The process loops as long as the condition expression is True. The program will exit from the statement block when the condition is False.
Example
MyList = INIRead("Examples", "", "", INIFile)
Keyword = ExtractString(MyList, nb, CR)
WHILE Keyword <> ""
nb = nb + 1
ExplName = INIRead("Projects installed", Keyword, "", INIFile)
Keyword = ExtractString(MyList, nb + 1, CR)
END
Syntax

"WHILE" condition Hide the details

WHILE <Condition>
  <Action if condition is True>
END
<WHILE>:
Marks the beginning of the statement block.
<Condition>:
Condition to check.
<Action if condition is True>:
Action to perform if the condition is True.
<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.
Remarks

Code to run

The code to run is found between the WHILE statement and the END statement.

Exiting from a WHILE loop

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

Loop without end

When compiling the project, a WHILE loop without an obvious end (BREAK, RETURN or RETURN statement missing) is signaled by a warning.

Running the next iteration

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

Composite condition

The AND and OR keywords are used to perform logical operations and to create composite conditions.
For example:
WHILE Price < 100 AND ProductType = "AA"
NumProduct ++       // Number of products whose price is less than
 // 100 and whose type is "AA"
END
 
WHILE Price > 100 OR Price < 500
 NumProduct ++  // Number of products whose price is included between €100 and €500
END
The conditions made of AND and OR are entirely evaluated.
For example:
A1 > 10 AND B1 < 20
Even if the first condition (A1 > 10) is false, the second condition (B1 < 20) will be checked.
Optimizing the evaluation of composite conditions: Use the _AND_ and _OR_ keywords. If the first condition is false (A1 > 10 in our example), the second condition (B1 < 20 in our example) will not be checked.
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemplo While
Exemplo While

_contador is int=0
WHILE _contador <200
_contador++
Trace(_contador)

END

//Blog com Video e Exemplo

http://windevdesenvolvimento.blogspot.com.br/2016/10/aula-936-windev-comandos-3-while.html

https://www.youtube.com/watch?v=xTql7tAzhyg

De matos
10 Oct. 2016

Last update: 05/26/2022

Send a report | Local help