xxxxxxxxxx
def iterate(L):
for index, item in enumerate(L):
print(f'{item} at index: {index}')
iterate([3, 5, 2, 1])
xxxxxxxxxx
lst = [10, 50, 75, 83, 98, 84, 32]
for x in range(len(lst)):
print(lst[x])
xxxxxxxxxx
# Python list
my_list = [1, 2, 3]
# Python automatically create an item for you in the for loop
for item in my_list:
print(item)
xxxxxxxxxx
# Python3 code to iterate over a list
list = [1, 3, 5, 7, 9]
# Using for loop
for i in list:
print(i)
xxxxxxxxxx
# Python3 code to iterate over a list
list = [1, 3, 5, 7, 9]
# Using for loop
for i in list:
print(i)
xxxxxxxxxx
List<int> list = new List<int> { 1, 2, 3, 4, 5 };
//For Loop
for (int i = 0; i < list.Count(); i++)
{ Console.WriteLine(list[i]); }
//For Each Loop
foreach (int item in list)
{ Console.WriteLine(item); }