How to write conditions inside the loops: ========================================= Syntax: initialization while condition: statement-1 if condition-2: statement-2 statement-3 else: statement-4 statement-5 update next statement (optional) # WAP TO FIND THE SUM OF EVEN NUMBERS AND ALSO ODD NUMBERS FROM THE GIVEN RANGE. """ n1 = 50 # first n2 = 150 # last evens ==> 50, 52, 54, 56, .... odds ==> 51, 53, 55, 57,.... sum_evens ==> 50 + 52 + 54 + 56 + .... sum_odds ==> 51 + 53 + 55 + 57 + .... """ # using while loop n1 = int(input("Enter first value of the range:")) n2 = int(input("Enter last value of the range:")) s_even = 0 s_odd = 0 n = n1 # initialization while n <= n2: # condition # giving the condition for even number checking if n % 2 == 0: s_even = s_even + n else: s_odd = s_odd + n n = n + 1 # update print("The Sum of Even numbers = ",s_even) print("The Sum of Odd numbers = ",s_odd) Syntax: for LoopVariable in range(start, stop, step): statement-1 if condition-1: statement-2 statement-3 else: statement-4 statement-5 next statement n1 = int(input("Enter first value of the range:")) n2 = int(input("Enter second value of the raneg:")) s_even = 0 s_odd = 0 for n in range(n1,n2+1): if n % 2 == 0: s_even = s_even + n else: s_odd = s_odd + n print("The Sum of Even numbers = ",s_even) print("The Sum of Odd numbers = ",s_odd) =========================================================== i = 0 while i in range(10): print(i) i += 1 for i in range(10): print(i) Nested Loops: ============= Syntax: for LoopVariable in range(start, stop, step): # outer for loop for LoopVaribale1 in range(start, stop, step): # inner for loop statements initialization1 while condition-1: initialization2 while conditio-2: statements update2 statements update1 for LoopVariable in range(start, stop, step): initialization while condition: statements update statements for i in range(1,6): for j in range(100,601,100): print(j,end = " ") print("Hi, here it is outer for loop value = ") print(i) ========================================== # WAP TO PRINT ALL PALINDROME NUMBERS FROM THE GIVEN RANGE. """ Palindrome number ==> number == reverse(number) """ n1 = int(input("Enter start value of the range:")) n2 = int(input("Enter last value of the range:")) for i in range(n1, n2+1): n = i reverseNumber = 0 while n > 0: individual = n % 10 reverseNumber = reverseNumber * 10 + individual n = n // 10 if reverseNumber == i: print(i,end = " ") ============================================ Transfer Statements: ==================== 1) break ======== -> when we need to get the immediate termination from the loop, we can use "break". Syntax: break 2) continue =========== -> When we need to stop the current iteration and continue with the remaining iterations, we can use "continue" Syntax: continue Note: ==== break and continue always use within the loops. for i in range(1,21): if i == 10: # break continue print(i,end = " ") ================================================= For Practice: ============= https://pynative.com/python-if-else-and-for-loop-exercise-with-solutions/