Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 82 Online
OpenStudy (anonymous):

6.00 introuduction to computing problem set 1, question 3 . Hey there , i have been working on the thrid problem . after a while i checked the answer. i am reading through it just now . one thing that i am confused about is the true statements in the while loop. the balance = original balance . but the balance changes inside the for loop . would this not exit the while loop ?. Or does anything that happens inside the for loop not effect the while loop ?

OpenStudy (turingtest):

could you please link to the solution you are referring to?

OpenStudy (anonymous):

i have attached the solotion below

OpenStudy (turingtest):

the `while` loop condition is `while True`, so you cannot exit that loop unless you break out of it, return, or throw an error

OpenStudy (turingtest):

`True` is always true

OpenStudy (turingtest):

you can write a program as follows to convince yourself that `while True` will create an infinite loop: ``` i = 0 while True: print i i += 1 ``` just be prepared to force quit the program

OpenStudy (anonymous):

Ah ok i think i a understand , thanks for that . originally i thought the while true related to the first and and the second lines always being true . This was confusing me as the balancing was changing , meaning it was not true. But i see now that its not related at all. So essentially the while true is an infinite loop that will excute until it encounters a break. I get it now , thanks for your help

OpenStudy (turingtest):

you got it :) welcome!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!