PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Syntax 1: Browsing the array elements
  • Syntax 2: Browsing the values of the "Key" elements found in the array
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
FOR EACH is used to perform different types of browse operations on the associative arrays:
  • Browsing the elements of associative array.
  • Browsing the values of the elements found in the associative array.
Note: The FOR ALL, FOR EACH statements are accepted. The FOR EACH statement will be used in this documentation but it can be replaced by FOR ALL.
Versions 15 and later
The FOR EACH statement can also be used to browse the .Net objects that implement the IEnumerable interface.
New in version 15
The FOR EACH statement can also be used to browse the .Net objects that implement the IEnumerable interface.
The FOR EACH statement can also be used to browse the .Net objects that implement the IEnumerable interface.
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
// 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
Syntax

Browsing the array elements Hide the details

FOR EACH [ELEMENT] <Variable> [, <Key> [, <Counter>]] OF <Array> [WHERE <Condition>] [<Direction>]
    ...
END
<FOR EACH [ELEMENT]>:
Marks the beginning of 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 array value. 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>:
Versions 20 and later
iPhone/iPadApple WatchWindows Mobile Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
New in version 20
iPhone/iPadApple WatchWindows Mobile Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
iPhone/iPadApple WatchWindows Mobile Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
<Direction>:
Optional indicator for the browse 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 Hide the details

FOR EACH [ELEMENT] <Variable> OF <Array> = <Key> [WHERE <Condition>] [<Direction>]
    ...
END
<FOR EACH ELEMENT>:
Marks the beginning of 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 array value. 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>:
Versions 20 and later
iPhone/iPadApple WatchWindows Mobile Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
New in version 20
iPhone/iPadApple WatchWindows Mobile Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
iPhone/iPadApple WatchWindows Mobile Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
<Direction>:
Optional indicator for the browse 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.
Remarks

Syntax 1: Browsing the array elements

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: Browsing the values of the "Key" elements found in 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
Minimum required version
  • Version 11
This page is also available for…
Comments
Example Full
https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/3133-winformatica-example-hexecutesqlquery-with-break-and-filter-custom/read.awp
BOLLER
Mar. 29 2019