In This Chapter
Understanding logical operators
Using conditional statements to affect script flow
Creating loops to repeat tasks
Avoiding common loop pitfalls
Computers are simply oversized and overpowered calculators. Sometimes it's hard to explain this to the average nontechie, but everything we do on our computers — sending and receiving e-mail, browsing the Web, watching movies — all comes back to numbers! In fact, everything comes down to two numbers: 0 and 1 (nothing and something).
Take away all the fancy processor architecture, bus speeds, and cool case lights on a computer, and you have a machine that's good at adding ones and zeroes and also at comparing true and false. Everything else that you see, hear, and interact with on your computer is some sort of representation of these fundamental units.
In this chapter, you give your Windows PowerShell scripts a little more intelligence by building on these concepts of true and false to direct the flow of information through your scripts.
Logic is built around the premise of true and false values, which are known as Boolean values. In general, the digit 1 represents true, and the digit 0 represents false. Windows PowerShell, however, also has automatic variables that define the values of true and false — namely,
When working with Boolean values, you can use a set of operations to combine and compare them. These operations are
AND: When you compare two values by ...