Professional Documents
Culture Documents
Python Loop
Python Loop
Python Loop
Lesson 2.5
CHAPTER
2
In This Lesson
While Loop
For Loop
For..Else Loop
Loop Control Statements
Nested Loop
Python Loops
while(boolean expression):
(statement1)
(statement2)
...
(statementN)
Example 1:
i = 1
1
while i <= 5: 2
print(i) 3
4
i += 1
5
Example 2:
i = 1 *
while i <= 5: **
***
print("*" * i) ****
i += 1 *****
Example 3:
x = [2,5,9,13,25]
i = 0 2
while(i<len(x)): 5
print(x[i]) 9
13
i += 1 25