I understand to stop iterating a while loop you can either fulfill a condition or you can use a break command. For example
apples = 10
while apples > 0:
apples -= 1
or
while True:
if apples == 0:
break
else:
apples -= 1
However this is obviously a very basic example, and I'm not sure what is more useful, easy or professional in much larger examples of code. I get the feeling this might end up being more of a situation to situation thing, but still, I can't seem to find an answer on google. Thanks.
edit:
example of using the first example in a past project:
finished_adding_object = False
while finished_adding_object == False:
print "System >>> Please enter new " + cls.__name__ + " name. If the user doesn't want to create a new " + cls.__name__ + ", please enter \"exit\"."
pending_new_object = raw_input("User >>> ")
while pending_new_object == "exit":
print "System >>> Please confirm, the user wishes to abandon creating a new " + cls.__name__ + "? (y/n)"
abandon_confirmation = raw_input("User >>> ")
if abandon_confirmation == "y":
pending_new_object = None
finished_adding_object = True
elif abandon_confirmation == "n":
pending_new_object = None
elif abandon_confirmation != "n" or "y": # User told if input is invalid.
print "System >>> " + abandon_confirmation + " is an invalid command."