Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Applies the given function to each element of the array. The integer passed to the function indicates the index of element.
Namespace/Module Path: Microsoft.FSharp.Collections.Array
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
Array.iteri : (int -> 'T -> unit) -> 'T [] -> unit
// Usage:
Array.iteri action array
Parameters
action
Type: int -> 'T -> unitThe function to apply to each index and element.
array
Type: 'T[]The input array.
Remarks
This function is named IterateIndexed in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.
Example
The following code examples shows the differences between Array.iter, Array.iter2, Array.iteri, and Array.iteri2.
let array1 = [| 1; 2; 3 |]
let array2 = [| 4; 5; 6 |]
Array.iter (fun x -> printfn "Array.iter: element is %d" x) array1
Array.iteri(fun i x -> printfn "Array.iteri: element %d is %d" i x) array1
Array.iter2 (fun x y -> printfn "Array.iter2: elements are %d %d" x y) array1 array2
Array.iteri2 (fun i x y ->
printfn "Array.iteri2: element %d of array1 is %d element %d of array2 is %d"
i x i y)
array1 array2
Output
Array.iter: element is 1 Array.iter: element is 2 Array.iter: element is 3 Array.iteri: element 0 is 1 Array.iteri: element 1 is 2 Array.iteri: element 2 is 3 Array.iter2: elements are 1 4 Array.iter2: elements are 2 5 Array.iter2: elements are 3 6 Array.iteri2: element 0 of array1 is 1 element 0 of array2 is 4 Array.iteri2: element 1 of array1 is 2 element 1 of array2 is 5 Array.iteri2: element 2 of array1 is 3 element 2 of array2 is 6
Platforms
Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2
Version Information
F# Core Library Versions
Supported in: 2.0, 4.0, Portable