# Python if-else and loops python_with_shubham
June 17

This is the part - 2 series of the topic - learn python in a week if you know to program already

## If  Statement:-

An "if statement" is denoted by using the if keyword.

Example:-

Output:- x is lessar then y.

## Elif Statement:-

The "elif" keyword is used when "if" conditions is False.

Example:-

Output:- x is equal to y.

## Else Statement:-

The "else" keyword is used when "if" and "elif" conditons both are False.

Example:-  x = 350

y = 50

if (x <  y):

print("x is lessar then y.")

elif (x == y):

print("x  is equal to y.")

else:

print("x is greater than y.")

Output:- x is greater than y.

__________________________

# Loops in Python

### while Loop in Python:-  A while loop repeatedly executes instructions inside the loop while a certain condition remains valid.

Example:-    i = 5

while i > 0:

print (i)

i = i - 1

Output:-  5

4

3

2

1

### Break:- When working with loops, sometimes you may want to exit the entire loop when a certain condition is met. To do that, we use the break keyword.

Example:-   i = 1

while i < 6:

print(i)

if i == 3:

break

i += 1

Output:-  1

2

3

### Continue:-  The continue statement we can stop the current iteration, and continue with the next.

Example:-  i = 0

while i < 6:

i += 1

if i == 3:

continue

print(i)

Output:-  1

2

4

5

6

### for Loops in Python:- The for Loop executes a block of code repeatedly until the condition is satisfied.

Example-1:-  pets = ['cats', 'dogs', 'rabbits', 'hamsters']

for myPets in pets:

print (myPets)

Output:-   cats

dogs

rabbits

hamsters

Example-2:-   for i in range(5):                                                          print (i)                     Output:- 0

1

2

3

4

_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_

## More from the author ### Python if-else and loops 