O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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
True

For now, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required