Looping Statements in Python – This tutorial explains the two types of loops in Python briefly.
What are looping Statements in Python?
Looping statements are used to execute a block of one or more statements repeatedly for a fixed number of times or as long as a given condition remains true.
Types of Python Looping Structures
There are two main loop statements in Python as follows:
- while loop
- for loop
Python while Statement
Python provides a while loop statement. A while loop is used to repeatedly execute a block of one or more statements as long as a given condition remains true. The while loop terminates, if the given condition becoms false.
i=1 while i<=5: print(i) i+=1
The output will be: 1 2 3 4 5
The Python for Statement
The Python for Statement is used to iterate over the members of a sequence in order, executing the block of statements each time.
# arr is a list of colors arr = ['Red','Green','Blue'] for c in arr: print(c)
The output will be: Red Green Blue
Looping Statements in Detail
Click the following links for detailed tutorials on for loop and while loop:
Python while statement with Syntax and Examples in detail
1,007 total views, 1 views today