Python for loop fruits = ["apple", "banana", "cherry"] for x in fruits:      print(x)
If you want to iterarte over a sequence i.e. either a tuple, list, dictionary, a set or a string then in that case for loop is very useful.
Just like any other programming language, in python language the "for" keyword is less like them and works like an iterator method as found in other object-oriented programming language.
A set of statements can be executed with the help of for loop, for each item in a list,tuple, set etc. for once.
For e.g. if we want to print each fruit in a fruit list:
An indexing variable is not required in the for loop to set beforehand.
for x in "banana":      print(x)
Looping Through a String
Strings contain a sequence of characters, so that's why they are also iterable objects:
For e.g. if we want to loop through the word "banana" then we need to write the following code:
The break Statement fruits = ["apple", "banana", "cherry"] for x in fruits:      print(x) if x == "banana":      break
The break statement is used if we want to stop the loop after a specific condition is being satisfied i.e. if a specific condition is satisfied during iteration through a loop then in that break statement is used.
For e.g. if we want to exit the loop when the value of x turns out to be banana, then we can write the following code:
The continue Statement fruits = ["apple", "banana", "cherry"] for x in fruits:      if x == "banana":          continue print(x)
The continue statement is used when we want to stop the current iteration of the loop and we want to continue with the next statement, then in that case continnue statement is used.
For e.g. if we do not want to print the banana from the following list, then we need to write the following code:
The range() Function for x in range(6):      print(x)
When we want to iterate through a loop for a specific number of times, then in that case we can use the range() function.
To loop through a set of code a specified number of times, we can use the range() function,
The output of range() function is a sequence of numbers that start from 0 and by default it gets incremened by 1 and ends at the specified number.
Using the range() function:
Else in For Loop for x in range(6): &nnbsp    print(x) else:      print("Finally finished!")
When the loop is finished then the block of code that is to be executed is put under the else block:
For e.g. if we want to printall numbers from 0 to 5 and a message when the loop has ended then we write the following code:
Nested Loops adj = ["red", "big", "tasty"] fruits = ["apple", "banana", "cherry"] for x in adj:      for y in fruits:          print(x, y)
A nested loop may be defined as a loop inside another loop.
In a nested loop the "inner loop" will be executed for the number of times specified for each iteration of the "outer loop".