2.1. Conditional Expressions

Before you learn to branch your program execution according to some condition, you must learn about conditional expressions. They are the means of checking if a condition is true, and they are the primary tool used in statements like if, switch, for, and while, which we will look into later in this chapter.

So, what is a conditional expression? Just like an arithmetic expression, a conditional one is a set of operations that are evaluated in order to compute a result. However, conditional expressions always evaluate to Boolean values, that is, they always return $true or $false. For example, this is how to check if the variable $num contains a number that is less than five:

PS> $num = 4
PS> $num -lt 5

For now, ...

Get Pro Windows PowerShell now with O’Reilly online learning.
