Generic considerations:
- I am currently programming in
python
; - I have a relatively simple level code;
- The code contains an instruction loop of type
while loop
;
I would like to know if there is a way to run the code specified below with an instruction of type for loop
, instead of while loop
:
soma = 0
i = 20
while i >= 0:
soma += -i
i = i - 2
print('Soma =',soma)
print('/'*30)
soma = 0
i = 20
I'm doing this:
soma = 0
i = 20
for i in range(20, 0, -2):
print('soma =', -i)
However, I do not get an output identical to the one I want
Thank you in advance for your help