ython Loops

WBOY
Release: 2024-07-25 00:04:32
Original
771 people have browsed it

ython Loops

Python Loops
Python has two primitive loop commands:

*while loops
for loops *

The while Loop:

With the while loop we can execute a set of statements as long as a condition is true.

`i = 1
while i < 6:
print(i)
i += 1

Output :

1
2
3
4
5
`
For loop:

A "For" Loop is used to repeat a specific block of code a known number of times

fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
Output :
apple
banana
cherry

Type of Loops:

For Loop. A for loop in Python is used to iterate over a sequence (list, tuple, set, dictionary, and string). Flowchart: .....

**While Loop. **The while loop is used to execute a set of statements as long as a condition is true. ...

**Nested Loop. **If a loop exists inside the body of another loop, it is called a nested loop.

The above is the detailed content of ython Loops. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template