I am a python newbie and have been asked to carry out some exercises using while and for loops. I have been asked to make a program loop until exit is requested by the user
Here's a solution (resembling the original) that works:
User = raw_input('Enter only to exit: ')
while True:
#Run my program
print 'In the loop, User=%r' % (User, )
# Check if the user asked to terminate the loop.
if User == '':
break
# Give the user another chance to exit.
User = raw_input('Enter only to exit: ')
Note that the code in the original question has several issues:
if/else is outside the while loop, so the loop will run forever.else is missing a colon.if clause performs a break.