From the course: Complete Guide to PowerShell 7
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
While and do-while loops - PowerShell Tutorial
From the course: Complete Guide to PowerShell 7
While and do-while loops
- [Instructor] Now there are a couple of other options for looping, and one of these is doing what's called a while loop. So a while loop is very much like we're iterating, such as with a four or a four each. But what it does, it's saying, well, keep iterating while we haven't got this value or we've matched something. So I'm going to do that same count option again where it says count equals five. And then what I'm going to do is say, while the count is greater than zero, write the output. Once the output's been written, then I want you to take a value away. So what we should now see is five, four, three, two, one, which is exactly a counting down scenario. So it means that the while is going to keep going until this criteria that says count greater than zero is kind of met. And then we're just going to keep taking values away. Now we also have what's called a do while loop. A do while loop is very similar to a while, but basically it's just going to say, well, we keep doing it until…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Introduction to flow control5m 46s
-
(Locked)
Using if, else, and switch statements6m 32s
-
(Locked)
For and foreach loops4m 48s
-
(Locked)
While and do-while loops3m 19s
-
(Locked)
Introduction to error handling4m 13s
-
(Locked)
Using try, catch, and finally blocks4m 32s
-
(Locked)
Throwing custom errors2m 22s
-
(Locked)
Debugging PowerShell scripts7m 11s
-
(Locked)
-
-
-
-
-
-