[Tutor] infinite while loop

Alan Gauld alan.gauld at yahoo.co.uk
Sat Oct 2 08:05:06 EDT 2021


On 02/10/2021 10:13, Marcus Lütolf wrote:
> Thank you. 
> The previousBalance is set back to 1000 after each run oft he for loop intentionally for the
> following for loops should run with minimumFixedMonthlyPayment each time increased by 10
> til previousBalance get's negative.

but you do that insie the while loop, so at the end of the loop it is
always 1000. So the loop never ends.

Try setting it at the top of the while loop, before entering the for loop.

> The while loop  should then stop, when   previousBalance  gets smaller than 0 but it doesn't.

The while loop only tests the value at the end of the loop block,
it does not detect changes inside the loop. So you need to ensure that
the value at the end of the loop is the one you want to be tested.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list