In [ ]:
count_up = 0

for i in range(2,17,2):
    count_up -= i   # count_up = count_up - i
    print(i, count_up)

In [ ]:
mylist = [1,6,2,19,-4,27,3]

accumulate = 0

for val in mylist:
    accumulate += val
    print(val, accumulate)

In [ ]:
import numpy as np

In [ ]:
my_array = np.arange(15)
array_2 = np.arange(2,17,1)

In [ ]:
print(my_array, array_2)

In [ ]:
for val1, val2 in np.nditer([my_array, array_2]):
    print(val1, val2, val1+val2)

In [ ]:
x = -3.0

while x < 9.3:
    print(x)
    x += 1.5
    
print("after the loop, x =", x)

what have we learned?

  • Loops are one way that a computer program does a bunch of things over and over again
  • In python: for and while loops
  • For loops - loop over a range, a list, or an array (nditer in numpy)
  • While loops go until some condition is met
  • Choose for vs. while for looping depending on circumstance

In [ ]: