Skip to content
Categories:

For Loop Powershell

Post date:
Author:

Looping until a value is reach

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# For loop interates a number of times
for ($f = 0; $f -le 5; $f++)
{
  "`$f = $f"
}


# Note the initializer can be set seperately
$f = 2
for (; $f -le 5; $f++)
{
  "`$f = $f"
}


# Iterating over a collection 1 by 1
$array = 11,12,13,14,15   # Simple Array
for ($i=0; $i -lt $array.Length; $i++)
{
  "`$array[$i]=" + $array[$i]
}