'''Python has two primitive loop commands: while loops for loops''' #while : repeat the operationa as long as condition is true '''while condition: #code''' #example: '''i = 1 while i < 6: print(i) i += 1''' #break # break used to stop or end the loop under specific condition """i = 1 while i < 6: print(i) if i == 3: break i += 1""" # continue: used to skip a secific step in while according to condtion '''i=0 while i < 6: i += 1 if i == 3: continue print(i) ''' #else: excuted when while loops end '''i = 1 while i < 6: print(i) i += 1 else: print("i is no longer less than 6")''' ################################################################33 #for loop:used for iterating over a sequence (that is either a list a string). #####loop through a list fruits =["apple", "banana", "cherry"] ''' fruits[0] = fruits[0] +"a" fruits[1] = fruits[1] +"a" fruits[2] = fruits[2] +"a" print(fruits)''' '''i = 0 for x in fruits: fruits[i] = x + "a" i += 1 print(fruits) ''' #####loop through a string '''for x in "banana": print(x+"#"*5)''' #break : we can stop the loop before it has looped through all the items '''fruits1 =["apple", "banana", "cherry"] for x in fruits1: print(x) if x == "banana": break ''' '''fruits2 = ["apple", "banana", "cherry"] for x in fruits2: if x == "banana": break print(x)''' #continue : the continue statement we can stop the current iteration of the loop, and continue with the next '''fruits3 = ["apple", "banana", "cherry"] for x in fruits3: if x == "banana": continue print(x)''' #range(): To loop through a set of code a specified number of times '''for x in range(6): print(x)''' '''for x in range(2, 7): print(x)''' #Else: specifies a block of code to be executed when the loop is finished '''for x in range(6): print(x) else: print("Finally finished!")''' #Nested Loops: The "inner loop" will be executed one time for each iteration of the "outer loop" adj = ["red", "big", "tasty"] fruits5 = ["apple", "banana", "cherry"] for x in : for y in fruits5: print(x, y)