AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Sintaxis WLanguage / Instrucciones estructuradas
  • Syntax 1: Iterating over elements in the array
  • Syntax 2: Browse element values of the array
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
FOR EACH is used to perform different types of browse operations on the associative arrays:
  • Browse the elements of the associative array.
  • Browsing the values of the elements found in the associative array.
Note: The FOR EACH, FOR ALL statements are accepted. The FOR EACH statement will be used in this documentation but it can be replaced with FOR ALL.
The FOR EACH statement can also be used to browse the .Net objects that implement the IEnumerable interface.
Ejemplo
// Declare an associative array of integers 
// Array indexed on strings and without duplicates
aaIDPerCustomer is associative array of int
aaIDPerCustomer["A"] = 55 // Add the identifier of customer "A"
aaIDPerCustomer["B"] = 321 // Add the identifier of customer "B"
aaIDPerCustomer["A"] = 56 // Modify the identifier of customer "A"
// Browse all the identifiers (syntax 1)
// 56
// 321
FOR EACH nIdentifier OF aaIDPerCustomer
	Trace(nIdentifier)
END
// Declare an associative array of integers
// This array is indexed on strings with duplicates
// Ignores the case and the accented characters
aaIDPerCustomer is associative array (WithDuplicates + ccIgnoreCasse + ccIgnoreAccent) of integers
aaIDPerCustomer["E"] = 55	 // add the identifier of customer "E"
aaIDPerCustomer["B"] = 321	// add the identifier of customer "B"
aaIDPerCustomer["e"] = 8	  // add the identifier of customer "e"
aaIDPerCustomer["é"] = 127	// add the identifier of customer "é"
// Browse all the identifiers of customers "E" (Syntax 2)
// 55
// 8
// 127
FOR EACH nIdentifier OF aaIDPerCustomer = "E"
	Trace(nIdentifier)
END
Sintaxis

Browsing the array elements Ocultar los detalles

FOR EACH [ELEMENT] <Variable> [, <Key> [, <Counter>]] OF <Array> [WHERE <Condition>] [<Direction>]
    ...
END
<FOR EACH [ELEMENT]>:
Marks the beginning of the statement block. The ELEMENT keyword is optional.
<Variable>:
Variable whose type is identical to the type of the array elements. For the arrays of classes, the variable must be a Dynamic Class variable. There is no need to declare this variable.
Note: This variable is a reference to the value of the array. A modification of this variable in FOR EACH will also modify the value in the associative array.
<Key>:
Key of element browsed. There is no need to declare this variable.
<Counter>:
Integer variable containing the number of iterations. There is no need to declare this variable.
<Array>:
Array to browse.
<Condition>:
WEBDEV - Código Servidor Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
<Direction>:
Optional indicator for the iteration direction.
FromBeginning
(default value)
Browse the array in the order of additions into the array.
FromEndBrowse the array in the reverse order of additions into the array.

Browsing the values of the "Key" elements found in the array Ocultar los detalles

FOR EACH [ELEMENT] <Variable> OF <Array> = <Key> [WHERE <Condition>] [<Direction>]
    ...
END
<FOR EACH ELEMENT>:
Marks the beginning of the statement block. The ELEMENT keyword is optional.
<Variable>:
Variable whose type is identical to the type of the array elements. For the arrays of classes, the variable must be a Dynamic Class variable. There is no need to declare this variable.
Note: This variable is a reference to the value of the array. A modification of this variable in FOR EACH will also modify the value in the associative array.
<Array>:
Array to browse.
<Key>:
Value of the key for which the array elements must be browsed. For an associative array without duplicates, 0 or 1 element will be browsed. For an associative array with duplicates, 0 or N elements will be browsed.
<Condition>:
WEBDEV - Código Servidor Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
<Direction>:
Optional indicator for the iteration direction.
FromBeginning
(default value)
Browse the array in the order of additions into the array.
FromEndBrowse the array in the reverse order of additions into the array.
Observaciones

Syntax 1: Iterating over elements in the array

For each iteration, <Variable> directly refers to the current element in the array. If the value of <Variable> is modified, the current element in the array is modified.
When exiting from the loop (standard exit or via the BREAK statement), the value of the last element read is assigned to <Variable> but <Variable> does not directly refer to the array element anymore.
Example:
// Declare an associative array of integers 
// Array indexed on strings and without duplicates
aaIDPerCustomer is associative array of int
aaIDPerCustomer["A"] = 55 // Add the identifier of customer "A"
aaIDPerCustomer["B"] = 321 // Add the identifier of customer "B"
aaIDPerCustomer["A"] = 56 // Modify the identifier of customer "A"
// Browse all the identifiers
// 56
// 321
FOR EACH nIdentifier OF aaIDPerCustomer
	Trace(nIdentifier)
END

Syntax 2: Browse element values <Clé> of the array

This syntax browses all the array elements with the specified <Key> value. For each iteration, <Variable> directly refers to the current element in the array. If the value of <Variable> is modified, the current element in the array is modified.
This syntax is useful when browsing associative arrays with duplicates. In an associative array without duplicates, the number of elements browsed can be 0 or 1. In an associative array with duplicates, the number of elements browsed can be 0 or N.
The array elements are browsed in the order of additions (no direction option).
When exiting from the loop (standard exit or via the BREAK statement), the value of the last element read is assigned to <Variable> but <Variable> does not directly refer to the array element anymore.
Example:
// Declare an associative array of integers
// This array is indexed on strings with duplicates
// Ignores the case and the accented characters
aaIDPerCustomer is associative array (WithDuplicates + ccIgnoreCasse + ccIgnoreAccent) of integers
aaIDPerCustomer["E"] = 55	 // add the identifier of customer "E"
aaIDPerCustomer["B"] = 321	// add the identifier of customer "B"
aaIDPerCustomer["e"] = 8	  // add the identifier of customer "e"
aaIDPerCustomer["é"] = 127	// add the identifier of customer "é"
// Browse all the identifiers of customers "E"
// 55
// 8
// 127
FOR EACH nIdentifier OF aaIDPerCustomer = "E"
	Trace(nIdentifier)
END
Versión mínima requerida
  • Versión 11
Esta página también está disponible para…
Comentarios
Example Full
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/3133-winformatica-example-hexecutesqlquery-with-break-and-filter-custom/read.awp
BOLLER
29 03 2019

Última modificación: 20/06/2025

Señalar un error o enviar una sugerencia | Ayuda local