Hi
I am creating a loop, and for one of the ?possibilities (or answer things or whatever they're called when you can execute commands from the results) i have a result of None.

This is the code.

ready = False
while not ready:
input = raw_input("Are you ready?")
if input is not None:
print 'you said something'
else:
done = True

This is a half-finished transitional code thing, but what I am trying to get this code to do is: repeatedly ask someone if they are ready, until they say "yes" in which case the code continues, or if they say "go away" then the program will exit.

And anyway, to achieve this, I (think I) have to make a variable of None equalling '' (or do I?) and every time i run the program I get SyntaxWarning-s.
Is there any way to stop these errors?

This works:

while True:
    input = raw_input("Are you ready?")
    if input:
        print 'you said something'
    else:
        print 'you said nothing'
        break

Yes in C sometimes people would make endless loops example

for(;;)

and then use and if statement to break it giwever if you feel you want to use if try using if 1 and continue

Python uses 'while True' for the endless loop.

# this will loop until the user enters
# either 'yes' or 'go away'
 
while True:
    quest = raw_input("Are you ready?")
    if quest == 'yes':
        break
    elif quest == 'go away':
        raise SystemExit
 
# more code here to be executed after break
print 'ouside of loop'
This article has been dead for over six months. Start a new discussion instead.