How it works...
Some of you might be pointing out that the foreach construct was simpler than the for construct in this case, and you would be right. In my stint as an administrator, I may have used the for construct fewer than 10 times over the last three years, compared to the hundreds of times I used foreach. The For construct has its own uses; use with a predefined array is one of the less-efficient ones.
Regardless, for works as long as the object is an array. $CurrentGuest is the index we use, which ranges from 0 through the total elements in $Guests—1. The loop starts with the index being initialized at 0 in this case, and after every iteration of the script block, the index is incremented ($CurrentGuest++).
One operation where for ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access