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

confused on basic while loop: http://codepad.org/q2TNoVoc the code will run while something is True. What is the true/false value in this function? confused on basic while loop: http://codepad.org/q2TNoVoc the code will run while something is True. What is the true/false value in this function? @MIT 6.00 Intro Co…

OpenStudy (anonymous):

It's an infinite loop, since the expression tested by the initial loop statement (in line 2) will always evaluate to true ('True' always has a value of true)

OpenStudy (anonymous):

so it will continue to loop even if it gets a correct value?

OpenStudy (anonymous):

Yes, so you need an alternative way to break out of the loop, in this case the return statement which immediately exits the entire function. You can also use "break", which exits the innermost loop only.

OpenStudy (anonymous):

did you test it? looks like it will work. it will loop till the conversion at line 5 works, then the function will return. when the function returns, the while loop 'no longer exists'. 9.1 and 9.2 of the tutorial are a good read http://docs.python.org/tutorial/classes.html#a-word-about-names-and-objects

OpenStudy (anonymous):

i will start using break to exit loops, thanks for the link to the tutorial.

OpenStudy (anonymous):

the tutorial should be installed on your computer along with the other documentation - F1 from within IDLE (windows).

OpenStudy (anonymous):

you don't have to use break, you can use a variable or an expression with a while statement http://codepad.org/sHnw1guC

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!