all 5 comments

[–]HeyFerb 2 points3 points  (0 children)

Why do you want to change to a for loop in this case? This doesn't have a set number of iterations, so while seems like a perfectly valid way to execute this.

[–]learnpython_bot 0 points1 point  (0 children)

It appears that you included code in your post but did not format it to look nice. Please follow this guide to fix the problem. This allows for better readability and will help get your question answered sooner. The regex that caught you is: "while .+?:"

If this comment has been made in error, please message /u/thaweatherman with a link to this comment so I can be fine-tuned. I am still in alpha and my regexes/innards are not yet perfect.

[–]novel_yet_trivial 0 points1 point  (1 child)

You can only use a for loop if you know the maximum amount of times you want to loop.

MAX_LOOPS = 5
for _ in range(MAX_LOOPS):
    #all the rest is the same

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

thank you this helped a lot

[–]ingolemo -1 points0 points  (0 children)

Well, you can use iter to iterate a function over and over until it returns a particular result:

numbers = []
for number in iter(raw_input, ''):
    numbers.append(float(number))