Junior — Middle
Explain what is meant by iteration in programming.
sobes.tech AI
Answer from AI
Iteration in programming is the process of sequentially traversing elements of a collection or repeating a specific block of code multiple times. Typically, iteration is used to process each element of a list, array, or other iterable object.
For example, in Python, you can iterate over a list using a for loop:
fruits = ['apple', 'banana', 'cherry']
for fruit in fruits:
print(f'I love {fruit}')
Here, the for loop performs iteration over each element of the fruits list and outputs a message for each one.