PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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).
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
FOR Subscript = 1 TO 10
        MyArray[Subscript] = MyVariable + 10
END
FOR Subscript = 10 TO 1 STEP -1
        MyArray[Subscript] = MyVariable + 10
END
FOR Subscript = 1 TO 5
        Trace(Subscript)
END
Info(Subscript)           // Subscript is set to 6
// Optimized syntax
// Browse the table rows.
// The number of rows is calculated once only
FOR Subscript = 1 _TO_ TABLE_MyTable..Occurrence
        COL_MyCol[Subscript]..Color = iDarkGreen
END
Syntax
FOR <Control variable> = <Initial value> TO <Final value> [STEP <x>]
...
END
<FOR>:
Marks the beginning of 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 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).
  • RESULT: 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 RESULT cannot be used in the same process.

Running the next iteration

To directly run the next iteration without ending the code of the next 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 required version
  • Version 9
This page is also available for…
Comments
Exemplo for Table
Exemplo for Table

FOR EACH ROW OF TABLE_string
Trace(TABLE_string.COL_Codigo+" "+TABLE_string.COL_Nome+" "+TABLE_string.COL_Preco+CR)
END

//Blog com video e Exemplo

http://windevdesenvolvimento.blogspot.com.br/2016/10/aula-940-windev-comandos-8-for-table.html

https://www.youtube.com/watch?v=IADIH7qb0X0
De matos
Oct. 14 2016
Ler Tabela Clientes
//exemplo 1 //Ler tabela Clientes
Trace("TODOS CLIENTE")
FOR ALL cliente
Trace(cliente.razao_social_nome)
END
// exemplo 2 // com filtro
Trace("CEP")
n_cep is int=93320428
FOR ALL cliente WHERE cliente.endereco_cep=n_cep
Trace(cliente.razao_social_nome)
END

//Blog com Video e Exemplo

http://windevdesenvolvimento.blogspot.com.br/2016/10/aula-938-windev-comandos-6-for-tabelas.html

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



De matos
Oct. 12 2016
Exemplo For
Exemplo For

n_contador is int=0
FOR n_contador =1 TO 10
Trace(n_contador)
END

FOR n_contador=10 TO 1 NOT-1
Trace(n_contador)
END

//Blog com Video e Exemplo

http://windevdesenvolvimento.blogspot.com.br/2016/10/aula-937-windev-comandos-5-for.html

https://www.youtube.com/watch?v=srq2bz_1qJM
De matos
Oct. 11 2016