0

how to correct this code

while (i < 10) : if ( i ==5 ): continue Else : print (i) i = i + 1

21st Jun 2019, 4:18 AM
mohan borkar
mohan borkar - avatar
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.
21st Jun 2019, 4:27 AM
voja
voja - avatar
+ 3
You don't need parentheses for your conditions in an if clause or loop. if x == y:, not if(x == y):
21st Jun 2019, 5:10 AM
Anna
Anna - avatar
+ 2
i = 0 while (i < 10): if i != 5 print i i += 1
21st Jun 2019, 4:25 AM
Jackson O’Donnell
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
21st Jun 2019, 6:45 AM
mohan borkar
mohan borkar - avatar