0
how to correct this code
while (i < 10) : if ( i ==5 ): continue Else : print (i) i = i + 1
4 ответов
+ 8
Here:
i= 3
while (i < 10) :
if ( i ==5 ):
break
else :
print (i)
i = i + 1
I will assume that this is a Python code.
1.First you need to initialize variable i ( i= 3 or some other number).
2. else should be lowercase.
3. continue doesn't make sense here. If i= 5 then you will end up with an infinite loop. You should use break.
+ 3
You don't need parentheses for your conditions in an if clause or loop. if x == y:, not if(x == y):
+ 2
i = 0
while (i < 10):
if i != 5
print i
i += 1
0
Thank you each one of you, I think I also had a logical error there. The corrected code is (as per my requirement) is as below. (please note that other good logic also exist )
i = 0
while i<=10 :
if ( i == 5 ):
i = i + 1
continue
else :
print (i)
i = i + 1