I am trying to convert these two for loops to while loops:
sum = 0
for i in range (10, 30):
for j in range(i, 10*i):
What for i in range(a,b)
does is it runs the loop for value of i
starting from a
till it reaches b-1
, same you can replecate with while loop statement. What we are doing here is before starting the loop we initiated i
to be qual to a and then keep on increasing the value by order of 1 after each iteration.
And before starting next iteration if it's less that b
if not we don't start the next iteration.
Watch this tutorial for more info.
sum = 0
i = 10
while i <30:
j=i
while j < (10*i):
sum += j
j+=1
i+=1