The Foreach loop and the For loop are different in that the latter uses an index to perform operations. We need a variable to control the flow, whose values form a range. Let's re-implement the same solution that we used in the Writing a more complex loop on a predefined array recipe, but with a For loop construct instead.
Using the For loop construct
How to do it...
The assumptions that are made are the same as those in the Writing a more complex loop on a predefined array recipe. Follow these steps to get started:
- Open a new file and paste the following content into it:
$Guests = Import-Csv './ch07/05-Write-GuestSeatDetails.csv' for ($CurrentGuest = 0; $CurrentGuest -lt $Guests.Length; $CurrentGuest++)...