Loops in Python

For Loops

for item in iterable_object:
    print(item)
# This is the syntax for loops in python
# Item represents the iterator's position
# You can call it anything you want
# printing numbers using for loops
for number in range(1,100):
    print(number)
# This will print numbers from 1 to 99
for letter in "Hello":
    print(letter)
# This for loop will print out the characters in the word hello

Ranges

x = input('How many times I have told you clean the room ')
y = int(x)
for time in range(y):
    print(f'{time}: Clean Your room')
# A simple example of loops

While Loops

while some_condition:
    #do this
# An example 
user_input = None
while user_input != 'please':
    print('Sorry Access Denied')
#Another While Loop Example
num = 0
while num < 10:
    num +=1
    print(num)

Importance of Break keyword in Python

while True:
    command = input('Type exit to get out of this')
    if command == 'exit':
        break


for x in range(1,10):
    if x == 3:
        break