Loops are super useful when you're working with lists and arrays! They help you go through each item without having to write the same code over and over.
One of the most common ways to loop is by using a for loop. Here’s what it looks like:
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
This code will show each fruit from the list one by one.
Another way to loop is with a while loop. This type of loop keeps going until a certain condition isn’t true anymore:
i = 0
while i < len(fruits):
print(fruits[i])
i += 1
Both of these methods make it easy to work with and access each item in your list!
Loops are super useful when you're working with lists and arrays! They help you go through each item without having to write the same code over and over.
One of the most common ways to loop is by using a for loop. Here’s what it looks like:
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
This code will show each fruit from the list one by one.
Another way to loop is with a while loop. This type of loop keeps going until a certain condition isn’t true anymore:
i = 0
while i < len(fruits):
print(fruits[i])
i += 1
Both of these methods make it easy to work with and access each item in your list!