WhileandForLoop_Notes
WhileandForLoop_Notes
Python While Loop: is used to execute a block of statements repeatedly until a given
condition is satisfied. When the condition becomes false, the line immediately after the loop
in the program is executed.
Example1: In this example, the condition for while will be True as long as the
counter variable (count) is less than 3.
count = 0
while (count < 3):
count = count + 1
print("Hello")
Output
Hello
Hello
Hello
Python For Loop: The For Loops in Python used for repeated execution of a group of
statements for the desired number of items. For loop is used for iterating over a sequence like
a String, Tuple, List, Set, or Dictionary.
list = [1,2,4,6,88,125]
for i in list:
print(i)
Output
1
2
4
6
88
125
given_number = 5
for i in range(11):
print (given_number, " x" , i , " =", 5*i )
Output
5x0=0
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50