INFINITE LOOPS ============= LOOP/ITERATION WHEN A BLOCK OF STATEMENTS WANT TO EXECUTE AGAIAN AND AGAIN BASED ON CONDITION WHILE LOOP, FOR LOOP NESTED LOOPS INFINITE LOOPS ==> ALLOW TO MAKE EXECUTE THE BLOCK OF CODE FOR INFINTE NUMBER OF TIMES. REASONS: 1) WHEN THE GIVEN CONDITION IS INCORRECT. 2) WHEN THE UPDATE IS INCORRECT 3) WHEN TH UPDATE STATEMENT IS MISSING i = 1 while i <= 10: print("Hello World!") # i += 1 missing of update statement ====================================== i = 1 while i > 0: # when the condition is incorrect print("Hello World!") i += 1 ============================== i = 1 while i <= 10: # when the condition is incorrect print("Hello World!") i -= 1 ==> to make interrupt an infinite loop execution, keyboard interrupt ==> Ctrl + c Applications ========== 1) client-server model ex: smart phone with sim network start calling texting browsing etc. 2) gaming development cricket ==> common shots ========================================== Transfer Statements ================ ==> also called as "loop controlling statements" ==> when we want stop/terminate the execution of loop body immediately. ==> when we want to skip some iteration and continue with remaining. ==> two types: 1) break statement 2) continue statement Note: ==== No goto statement in python. 1) break statement =============== here: break ===> keyword ==> to stop/terminate the loop body statements execution immediately. Syntax: break ==> we can allowed to use the break in only loops along with condition for i in range(20, 0, -1): # reverse accessing if i == 10: break print(i,end = "\t") ========================= i = 20 while i > 0: if i == 10: break print(i,end = "\t") i -= 1 ============================== for i in range(1,10): print(i, end="\t") break ============================ 2) continue statement ================= here: continue ===> keyword ==> when we want to pause/skip some iteration and continue with remaining iterations, continue statement is used. Syntax: continue ==> we can always use this continue statement in loops only. for i in range(1,11): if i == 6: continue print(i, end="\t") ===================== i = 10 while i > 0: if i == 6: i -= 1 continue print(i,end = "\t") i -= 1 ==> continue with condition in loops ==> suggested because, if the condition is missing with continue the loop will be executed as like normal loop. ================================================ patterns ====== ==> requirement: nested loops outerloop: innerloop: lines = int(input("Enter number of lines for pyramid structure:")) # 6 # row-wise operation for row in range(1,lines+1): # column-wise operation for col in range(1,row+1): print("*",end = " ") print() ============================== lines = int(input("Enter number of lines for pyramid structure:")) # 6 # row-wise operation for row in range(1,lines+1): # column-wise operation for col in range(1,row+1): print(row,end = " ") print() ==================== lines = int(input("Enter number of lines for pyramid structure:")) # 6 # row-wise operation for row in range(1,lines+1): # column-wise operation for col in range(1,row+1): print(col,end = " ") print() =============================== chr() ==== ==> accept an ASCII value ==> return: its corresponding character Syntax: chr(ASCII Value) ord() ==== ==> accept a character ==> return its corresponding ASCII Syntax: ord(character) lines = int(input("Enter number of lines for pyramid structure:")) # 6 value = 97 # starting point of upper case alphabet ASCII for row in range(1,lines+1): for col in range(1,row+1): result = chr(value) print(result,end = "\t") value += 1 print() ============================== symbol if symbol == '+': a + b elif symbol == '-': a - b else: incorrect operation