How do you do a while loop in python?

1 answer

Answer

1035197

2026-04-20 21:05

+ Follow

#LMGTFY

In this example, I have created an array of numbers called 'foobar', and while the variable 'sum' is less than 20, I will have the program continue to loop back and add the next number in the array sequence.

#!usr/bin/env

foobar = [1, 4, 7, 2, 9, 11, 0, 6, 5, 4, 16, 3]

sum = 0

iteration = 0

while(sum < 20):

sum += foobar[iteration]

iteration += 1

print("Finished!")

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.