At times, we will want to achieve different outcomes based on the state of our data within a script. This behavior is known as control flow and uses conditional statements and loops that allow us to execute our code in a desired fashion.

In this lesson, we’ll look at

  • if, else, and elseif statements
  • switch statements
  • for and foreach loops
  • while and dowhile and dountil loops
  • break and continue commands

Using the correct form of control flow will help create scripts with different behaviors that are easy to understand and improve upon.


Click Next to start learning about control flow in PowerShell.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?