for loop for list code example

Example 1: python loop through list

list = [1, 3, 6, 9, 12] 
   
for i in list: 
    print(i)

Example 2: list loop python

list = [1, 3, 5, 7, 9] 

# with index   
for index, item in enumerate(list): 
    print (item, " at index ", index)
    
# without index
for item in list:
  	print(item)

Example 3: for element in array python

itemlist = []
for j in range(len(myarray)):
    item = myarray[j]
    itemlist.append(item)

Example 4: java iterate over list

for (int i = 0; i < crunchifyList.size(); i++) {
            System.out.println(crunchifyList.get(i));
        }

Example 5: iterate through an arraylist java

// will iterate through each index of the array list
// using the size of the array list as the max.
// (the last index is the size of the array list - 1)

for (int i = 0; i < myArrayList.size(); i++) {
  
  System.out.println(myArrayList.get(i));
  // will print each index as it loops
}

Example 6: iterate through a list

my_list = ["Hello", "World"]
for i in my_list:
  print(i)

Tags:

Go Example