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 array elements
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 arrays:
  • Browsing the array elements,
  • Browsing the values of array elements.
Note: The FOR ALL, FOR EACH statements are accepted. In this documentation, we will be using the FOR EACH statement 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
WINDEV MobileiPhone/iPad This feature is available for the iPhone/iPad applications.
New in version 17
WINDEV MobileiPhone/iPad This feature is available for the iPhone/iPad applications.
WINDEV MobileiPhone/iPad This feature is available for the iPhone/iPad applications.
Versions 18 and later
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Windows Store apps mode.
WEBDEV - Browser code This feature is available in browser code.
WINDEV MobileAndroid Widget This feature is available in Android Widget mode.
New in version 18
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Windows Store apps mode.
WEBDEV - Browser code This feature is available in browser code.
WINDEV MobileAndroid Widget This feature is available in Android Widget mode.
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Windows Store apps mode.
WEBDEV - Browser code This feature is available in browser code.
WINDEV MobileAndroid Widget This feature is available in Android Widget mode.
Versions 21 and later
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Universal Windows 10 App mode.
WINDEV MobileApple Watch This feature is available in Apple Watch mode.
New in version 21
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Universal Windows 10 App mode.
WINDEV MobileApple Watch This feature is available in Apple Watch mode.
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Universal Windows 10 App mode.
WINDEV MobileApple Watch This feature is available in Apple Watch mode.
Example
// Browse the elements found in an array of reals and calculate the sum
// Fill the array
ArrCalc is array of 3 reals
ArrCalc[1] = 12.5
ArrCalc[2] = 10
ArrCalc[3] = 7.5
// Calculate the sum
TotalSum is real
FOR EACH AnElement OF ArrCalc
        TotalSum += AnElement
END
Versions 20 and later
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchWindows Mobile
// Browse the arrCustomers array and only process the customers
// whose city is equal to "MONTPELLIER".

stCustomer is Structure
Name is string
FirstName is string
City is string
END

arrCustomers is array of stCustomer

FOR EACH stACustomer OF arrCustomers WHERE City = "MONTPELLIER"
// Process
END
New in version 20
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchWindows Mobile
// Browse the arrCustomers array and only process the customers
// whose city is equal to "MONTPELLIER".

stCustomer is Structure
Name is string
FirstName is string
City is string
END

arrCustomers is array of stCustomer

FOR EACH stACustomer OF arrCustomers WHERE City = "MONTPELLIER"
// Process
END
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchWindows Mobile
// Browse the arrCustomers array and only process the customers
// whose city is equal to "MONTPELLIER".

stCustomer is Structure
Name is string
FirstName is string
City is string
END

arrCustomers is array of stCustomer

FOR EACH stACustomer OF arrCustomers WHERE City = "MONTPELLIER"
// Process
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 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.
<Key>:
Key of the element browsed. This key depends on the element browsed:
  • One-dimensional array: subscript of the element in the array.
  • Two-dimensional array (or n-dimensional array): counter that starts from 1
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
WINDEVWEBDEV - Server codeiPhone/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
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchWindows Mobile Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
WINDEVWEBDEV - Server codeiPhone/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 from the first element to the last one.
FromEndBrowse the array from the last element to the first one.

Browsing the values of array elements Hide the details

FOR EACH [ELEMENT] <Value> OF <Array> [WHERE <Condition>] [<Direction>]
    ...
END
<FOR EACH ELEMENT>:
Marks the beginning of the statement block. The ELEMENT keyword is optional.
<Value>:
Variable whose type is compatible with the array elements. There is no need to declare this variable.
<Array>:
Array to browse.
<Condition>:
Versions 20 and later
WINDEVWEBDEV - Server codeiPhone/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
WINDEVWEBDEV - Server codeiPhone/iPadApple WatchWindows Mobile Condition to indicate to filter the browse. Only the array elements corresponding to the filter will be browsed.
WINDEVWEBDEV - Server codeiPhone/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 from the first element to the last one.
FromEndBrowse the array from the last element to the first one.
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.
All types of arrays are available: automatic, fixed, dynamic.
The arrays can have several dimensions.
The behavior is undefined if the number of elements is modified in the browse loop.

Syntax 2: Browsing the values of array elements

For each iteration, the value of the element browsed is assigned to the <Value> variable. If the value of <Value> is modified, the current element in the array is not modified.
All types of arrays are available: automatic, fixed, dynamic.
The arrays can have several dimensions.
The behavior is undefined if the number of elements is modified in the browse loop.
Minimum required version
  • Version 10
This page is also available for…
Comments
Vor For each
https://youtu.be/B9tZPrVs2aY
https://windevdesenvolvimento.blogspot.com/2019/04/dicas-2064-windev-arquivos-31-arquivo.html
sTexto is string=[
1|COURO|PR
2|CAMISA|UN
3|TENIS|PAR
]
FOR EACH STRING sLINHA OF sTexto SEPARATED BY CR
sCODIGO is string=ExtractString(sLINHA,1,"|")
NOME is string=ExtractString(sLINHA,2,"|")
UNIDADE is string=ExtractString(sLINHA,3,"|")
Trace("codigo="+sCODIGO+" nome="+NOME+" unidade="+UNIDADE)
END
amarildo
Apr. 04 2019