1D Traversal

To traverse around the array, for example from A to B (doesn't count B), we have 2 ways to traverse

[_,_,_,_,A,_,_,_,_,_,B,_,_,_,_]
 0,1,2,3,4,5,6,7,8,9,..........  index

Moving the index

This one is easy, we basically moving the index as we traverse.

for i in range(4, 10): 
	print(i) # 4,5,6,7,8,9

Without moving the index

Sometimes we don't want to move the index when we traverse. In that case, we have to traverse by the difference of index

currentIndex = 4
for i in range(10 - 4):
	print(currentIndex + i) # 4,5,6,7,8,9

Note:

  • 4: current index of A
  • 10: current index of B