February 2019
Intermediate to advanced
626 pages
15h 51m
English
The for loop is typically used to step through a collection using the following notation:
for (<intial>; <exit condition>; <repeat>){
<body-statements>}
<initial> represents the state of a variable before the first iteration of the loop. This is normally used to initialize a counter for the loop.
The exit condition must be true as long as the loop is executing.
<repeat> is executed after each iteration of the body and is often used to increment a counter.
The for loop is most often used to iterate through a collection, for example:
$processes = Get-Process
for ($i = 0; $i -lt $processes.Count; $i++) {
Write-Host $processes[$i].Name}
The for loop provides a significant degree of control over the loop and is useful where the step needs ...
Read now
Unlock full access