`while` Loop

This lesson will introduce us to the syntax and implementation of the `while` loop.

Introduction

The while loop also repeats a portion of code over and over, but if and only if a condition is met or is evaluated to True.

Syntax in python

while loop syntax in Python:

while condition:
    statement1
    statement2

Syntax in powershell

while loop syntax in PowerShell:

while (condition) {
    statement1
    statement2
}

Example

A simple example of a while loop in Python can be printing numbers from 1 to 10 that are even.

Get hands-on with 1200+ tech skills courses.