I'm confused about the use of the continue
statement in a while
loop.
In this highly upvoted answer, continue
is used inside a while
loop to indicate that the execution should continue (obviously). It's definition also mentions its use in a while
loop:
continue may only occur syntactically nested in a for or while loop
But in this (also highly upvoted) question about the use of continue
, all examples are given using a for
loop.
It would also appear, given the tests I've run, that it is completely unnecessary. This code:
while True:
data = raw_input("Enter string in all caps: ")
if not data.isupper():
print("Try again.")
continue
else:
break
works just as good as this one:
while True:
data = raw_input("Enter string in all caps: ")
if not data.isupper():
print("Try again.")
else:
break
What am I missing?