[Tutor] Continue Statement
spir
denis.spir at gmail.com
Mon Dec 16 19:59:23 CET 2013
On 12/16/2013 03:12 PM, Alina Campana wrote:
> Hello dear tutorlist,
> I feel terribly ashamed for my bad english...
> Yet I'll try to form my question:
> It is about the continue statement in python.I wrote this code
> i = 0while (i < 10): if i == 5: continue print i i+=1
> What i expected was an output like12346789
> Instead it seems to freeze after 4. The shell input symbol is blinking.
>
> I bet this is easy enough for pros but I really got my problem with understanding the reason why.
> Okay thank you people, I go now learn better english ^^
Your english is as good as mine ;-)
In addition to what others has said:
There are many ways to do what you expected. The simplest one beeing to add a
variable. In fact, you have to increment i before the test that may lead to
"continue", else it is never incremented in case i=5; but you also need to keep
i at its present value for the rest of the present pass in the loop. Example
solution:
i = 0
while i < 10:
i_for_this_pass = i
i += 1
if i_for_this_pass == 5:
continue
print i_for_this_pass
(Well, the variable name is a bit long, but you see what it means ;-)
Denis
More information about the Tutor
mailing list