Untitled Document
Loops and Iterations - For and While Loops
```       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****
# FOR LOOPS
# Program - Simple for loop

# Ex-1 Lets write a simple for loop to itertae through a list
nums = [1, 2, 3, 4, 5]
for i in nums:
print(i)
```
```       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****
# Program - Break and Continue statements

# break - keyword will break out of loop ( terminate the loop) once the condition gets matched

nums = [1, 2, 3, 4, 5]
for i in nums:
if i == 3:
print("Found !!")
break
print(i)

# continue --> keyword will skip the current iteration on matching the conditions and continues with further iterations

nums = [1, 2, 3, 4, 5]
for i in nums:
if i == 3:
print("Found !!")
continue
print(i)
```
```       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****
# Program - Nested loop
# Here we will use a for loop within for loop ; just run the code and see the  o/p
#Nested loop  --> loop within a loop

nums = [1, 2, 3, 4, 5]
for num in nums:
for letter in 'abc':
print(num, letter)
```
4. Program - Iterating through a loop for a specific count or in a given range Click Here
```       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****
# Program - Iterating  through a loop for a specific count or in a given range
# Here we will use range function

for i in range(1, 11):
print(i)

```
```       #********* Source Code From Website - Mangadaku - visit us at -http://mangadaku.com/ *****
# Program - While loop basic example

x = 0
while x < 10 :
print(x)
x +=1

# break statement in while loop

x = 0
while x < 10 :
if x == 5 :
break
print(x)
x +=1
```
Untitled Document