PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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.
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.
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 statement block.
<Condition>:
Condition to check.
<Action if condition is True>:
Action to perform if the condition is True.
<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.
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).
  • RESULT: 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 RESULT cannot be used in the same process.

Loop without end

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

Running the next iteration

To directly run the next iteration without ending the code of the next 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 required version
  • 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
Oct. 10 2016