ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / Structured statements
  • Equivalent syntax
  • Code to run
  • Increment step
  • Exiting from a FOR loop
  • Running the next iteration
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 while a control variable is modified and compared to a limit value (before each beginning of statement block).
The statement block is run for each one of the values successively taken by the control variable. The initial value is assigned to the control variable during the first entry in the FOR statement.
An optimized syntax is available: this syntax prevents the end value and/or the step value from being re-evaluated at each iteration (useful for a loop on the number of table rows for example).
Example
FOR Index = 1 TO 10
MyArray[Index] = MyVariable + 10
END
FOR Index = 10 TO 1 STEP -1
MyArray[Index] = MyVariable + 10
END
FOR Index = 1 TO 5
Trace(Index)
END
Info(Index)    // Index is set to 6
// Optimized syntax
//Loop through rows in a Table control.
// The number of rows is calculated once only
FOR Index = 1_TO_TABLE_MyTable.Count
COL_MyCol[Index].Color = iDarkGreen
END
Syntax
FOR <Control variable> = <Initial value> TO <Final value> [STEP <x>]
...
END
<FOR>:
Marks the beginning of the statement block.
<Control variable>:
Scalar simple variable (integer or real).
There is no need to declare this variable. Indeed, this variable is automatically declared.
<Initial value>:
Initial value of control variable (integer or real).
<Final value>:
Final value of control variable (integer or real).
<STEP>:
Increment step (optional) of control variable (1 by default).
<x>:
Optional value of increment step (same type as the type of control variable).
<END>:
Marks the end of the statement block.

Other possible syntaxes Hide the details

FOR <Control variable> = <Initial value> _TO_ <Final value> [STEP <x>]
...
END

FOR <Control variable> = <Initial value> _TO_ <Final value> [_STEP_ <x>]
...
END

FOR <Control variable> = <Initial value> TO <Final value> [_STEP_ <x>]
...
END
<_TO_>:
Signals that the final value must be evaluated once only
<_STEP_>:
Signals that the increment step must be evaluated once only.
Remarks

Equivalent syntax

You also have the ability to use the following syntax:
FOR <Control variable> = <Initial value> TO <Final value> [STEP <x>]; ... ; END
The semicolon is used to separate the different lines.

Code to run

The code to run is placed between the FOR and END statements.

Increment step

The increment step of FOR statement must be constant. A warning is displayed during the project compilation if the increment step is likely to change at each iteration.

Exiting from a FOR loop

Several statements are available:
  • RETURN: Exit from the FOR loop and exit from the current process (or procedure).
  • RETURN: Return a status report to the calling process. Exit from the FOR loop and exit from the current process (or procedure).
  • BREAK: Exit from the FOR loop and run the rest of the current process.
Close is used to exit from the FOR 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:
FOR <Control variable> = <Initial value> TO <Final value> [STEP <x>]
...
IF <Condition> THEN CONTINUE   // Return to the FOR keyword
...
END
In this case, the control variable is automatically incremented.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help