if and else

elseif(conditional) syntax python change into elif(conditional)


a=99
b=75
c=60
print("A:",a,"B:",b,"C:",c)
if (a>b):
 print("a Greater then b")
elif(b>c):
 print("b Greater then c")
else:
 print("c smaller then a,b")
Output:
A: 99 B: 75 C: 60
a Greater then b

Loop

A loop statement allows us to execute a statement or group of statements multiple times.

  1. For
  2. While
  3. Nested

While

Repeats a statement or group of statements while a given condition is true. it the condition before executing the loop body.

Syntax:
	iterating_var
	 while(conditional):
	 			statements
	
		count=5
while (count>0):
	print("Hello...")
	count=count-1
print("Good Bye!")
	
Output:
Hello...
Hello...
Hello...
Hello...
Hello...
Good Bye!	

for

Repeats a statement or group of statements while a given condition is true.it tests the condition before executing the loop body.

Syntax:
	for iterating_var in sequence:

for x in range(2):
	print(x)

for x in range(1,2):
	print(x)	

for x in range(2,12,2):
	print(x)	
Output:
0
1
1
2
4
6
8
10	

Nested Loops

python programming language allows use of one loop inside another loop.This is called Nested Loop.

For

forinterating_var in sequence:
	forinterating_var in sequence:
	statements
statements	

for x in range(3):
	for x in range(1,3):
		print(x)
print(x)	
Output:
1
2
1
2
1
2
2	

while

while expression:
	while expression:
		statements
statements		
i=0
j=0
while (i<3):
	while (j<4):
		print("inner loop:",j)
		j=j+1
	i=i+1		
print("outer loop:",i)
print("say bye!")
Output:
inner loop: 0
inner loop: 1
inner loop: 2
inner loop: 3
outer loop: 3
say bye!