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 Tutorial (English)

Python Tutorial (Hindi)

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Python Variables
Python Decision Making Statements
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading