© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2021
I. WatersPowerShell for Beginnershttps://doi.org/10.1007/978-1-4842-7064-6_5

5. Loops

Ian Waters1  
(1)
Bexhill, UK
 

Loops are another really useful tool when writing scripts. Loops are great for running code multiple times based on the value of a variable. They can be useful for checking values in a list of variables.

I’ve bundled the code listed in this chapter into one file to make it easy for you to try each of the examples by highlighting the code and choosing “Run Selection” within Visual Studio Code.
# Each time around the loop the code in the brackets will run while $counter is less than than $repeat.
# Each time around the loop the ++ symbols tell the ...

Get PowerShell for Beginners: Learn PowerShell 7 Through Hands-On Mini Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.