2.2. Branching Instructions

Branching instructions bear that name, because they split program execution according to a conditional statement. Typically they specify several possible execution flows. At the time of execution, a statement is evaluated, and a code path is chosen according to the value returned from that statement. PowerShell offers two branching instructions: if/else that allows us to choose one of two code paths, and switch that selects and executes one of many alternatives.

2.2.1. Simple Branching: if/else

The simplest branching instruction in many mainstream programming languages is the if statement. It evaluates a conditional expression and executes one block of code if the result is true, another if false. The general form ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.