list iteration code example

Example 1: java loop through list

for (E element : list) {
    . . .
}

Example 2: java iterate over list

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

Example 3: iterate through a list

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

Example 4: list iteration

def count_v1(dna, base):
    dna = list(dna)  # convert string to list of letters
    i = 0            # counter
    for c in dna:
        if c == base:
            i += 1
    return i

Example 5: list iteration

>>> list('ATGC')
['A', 'T', 'G', 'C']