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

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…

Contents