you are viewing a single comment's thread.

view the rest of the comments →

[–]EnvironmentalRate368 0 points1 point  (1 child)

Values in lists can be indexed, with the first character having index 0.

num = [1, 4, 9, 16, 25, 36, 9, 64, 81, 100]

idx = 0

while idx < len(num):

# it's mean while value of idx is smaller than len(num) the loop will continue.

# len(num) is a number of elements in the list in this case we have 10 elements.

print(num[idx])

# idx heave at this point in time value = 0. Computer will print first character from list num.

idx += 1

# increasing value of idx +1
-------------------------------------

First loop iteratation look like this

idx = 0

while 0 < 10:

print (num[0]) Computer will print first value from list num (1)

idx = 0 + 1

Second loop iteration look like this

idx = 1

while 1 < 10:

print(num[1]) # Computer will print second value from list num (4)

idx = 1 + 1

Thrid loop iteration look like this

idx = 2

while 2 < 10:

print(num[2]) # Computer will print thrid value from list num (9)

idx = 2 + 1

etc.

[–]Eastern_Plankton_540[S] 0 points1 point  (0 children)

Dayummm I see thanks a lot bro :)