Mental Model
Go through each item in the list one by one to look at or use it.
Analogy: Like reading a book page by page from start to finish to understand the story.
Index: 0 1 2 3 4 Array: [5] -> [3] -> [8] -> [1] -> [7]
Index: 0 1 2 3 4 Array: [5] -> [3] -> [8] -> [1] -> [7]
Index: 0 ↑ 1 2 3 4 Array: [5] -> [3] -> [8] -> [1] -> [7]
Index: 0 1 ↑ 2 3 4 Array: [5] -> [3] -> [8] -> [1] -> [7]
Index: 0 1 2 ↑ 3 4 Array: [5] -> [3] -> [8] -> [1] -> [7]
Index: 0 1 2 3 ↑ 4 Array: [5] -> [3] -> [8] -> [1] -> [7]
Index: 0 1 2 3 4 ↑ Array: [5] -> [3] -> [8] -> [1] -> [7]
5 -> 3 -> 8 -> 1 -> 7
def traverse_array(arr): for i in range(len(arr)): print(arr[i], end=' -> ' if i < len(arr) - 1 else '\n') # Driver code array = [5, 3, 8, 1, 7] traverse_array(array)
for i in range(len(arr)):print(arr[i], end=' -> ' if i < len(arr) - 1 else '\n')for i in range(len(arr)):
print(arr[i], end=' -> ' if i < len(arr) - 1 else '\n')
for i in range(len(arr)):
print(arr[i])arr is a list of numbers.arr[i] accesses each element in order, printing them one by one.arr using a for-each style loop in Python?for variable in iterable to loop over elements directly.for element in arr, which correctly loops over elements. Others have syntax errors or misuse range.arr = [10, 20, 30, 40]
for i in range(1, len(arr)):
print(arr[i])
arr:arr = [1, 2, 3, 4]
for i in range(len(arr)):
print(arr[i+1])
arr = [3, 5, 7, 9, 11], write code to print elements at even indices only using array traversal patterns. Which code snippet does this correctly?range(0, len(arr), 2) which correctly iterates over even indices. Others either use odd indices or check element values incorrectly.Pass the test and this pattern moves unknown