Python Loops

Python Loops

Loops execute a block of code and this code executes while the condition is true. In this lesson, we will learn about Python Loops such as while loop, for loop, etc.

while loop in Python

In while loop, the block of code executes only when the condition is true. It executes as long as the condition is true.

Syntax

Here’s the syntax:

Example

The following is an example showing the usage of while loop in Python,

Output

The following is the output,

Python while loop

for loop in Python

The for loop in Python is used when you can set how many times a statement is to be executed.

Syntax

Here’s the syntax,

Example

The following is an example showing the usage of for loop in Python,

Output

The following is the output,

Python for loop

In this lesson we learned about the types of loops in Python.

Python Variables
Python Decision Making Statements
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create free tutorials for all.

No Comments

Post A Comment