|
1 |
| ---- |
2 |
| -ms.date: 11/28/2017 |
| 1 | +--- |
| 2 | +md.date: 2/27/2019 |
3 | 3 | schema: 2.0.0
|
4 | 4 | locale: en-us
|
5 | 5 | keywords: powershell,cmdlet
|
6 | 6 | title: about_Foreach
|
7 | 7 | ---
|
8 | 8 | # About ForEach
|
9 | 9 |
|
10 |
| -## SHORT DESCRIPTION |
11 |
| - |
| 10 | +## Short description |
12 | 11 | Describes a language command you can use to traverse all the items in a
|
13 | 12 | collection of items.
|
14 | 13 |
|
15 |
| -## LONG DESCRIPTION |
| 14 | +## Long description |
16 | 15 |
|
17 |
| -The Foreach statement (also known as a Foreach loop) is a language construct |
| 16 | +The `Foreach` statement (also known as a `Foreach` loop) is a language construct |
18 | 17 | for stepping through (iterating) a series of values in a collection of items.
|
19 | 18 |
|
20 | 19 | The simplest and most typical type of collection to traverse is an array.
|
21 |
| -Within a Foreach loop, it is common to run one or more commands against each |
| 20 | +Within a `Foreach` loop, it is common to run one or more commands against each |
22 | 21 | item in an array.
|
23 | 22 |
|
24 | 23 | ## Syntax
|
25 | 24 |
|
26 |
| -The following shows the ForEach syntax: |
| 25 | +The following shows the `ForEach` syntax: |
27 | 26 |
|
28 |
| -```syntax |
| 27 | +``` |
29 | 28 | foreach ($<item> in $<collection>){<statement list>}
|
30 | 29 | ```
|
31 | 30 |
|
@@ -54,7 +53,7 @@ string values `"a"`, `"b"`, `"c"`, and `"d"`. The first time the `Foreach`
|
54 | 53 | statement runs, it sets the `$letter` variable equal to the first item in
|
55 | 54 | `$letterArray` (`"a"`). Then, it uses the `Write-Host` cmdlet to display the
|
56 | 55 | letter a. The next time through the loop, `$letter` is set to `"b"`, and so
|
57 |
| -on. After the `Foreach` loop displays the letter d, Windows PowerShell exits |
| 56 | +on. After the `Foreach` loop displays the letter d, PowerShell exits |
58 | 57 | the loop.
|
59 | 58 |
|
60 | 59 | The entire `Foreach` statement must appear on a single line to run it as a
|
@@ -158,6 +157,8 @@ variable inside of a foreach script block. The example function can find
|
158 | 157 | functions in a script even if there are unusually- or inconsistently-spaced
|
159 | 158 | function definitions that span multiple lines.
|
160 | 159 |
|
| 160 | +For more information, see [Using Enumerators](about_Automatic_Variables.md#using-enumerators). |
| 161 | + |
161 | 162 | ```powershell
|
162 | 163 | function Get-FunctionPosition {
|
163 | 164 | [CmdletBinding()]
|
@@ -226,4 +227,4 @@ function Get-FunctionPosition {
|
226 | 227 |
|
227 | 228 | [about_If](about_If.md)
|
228 | 229 |
|
229 |
| -[ForEach-Object](../ForEach-Object.md) |
| 230 | +[ForEach-Object](../ForEach-Object.md) |
0 commit comments