[SOLVED] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
12th Jun 2022, 9:44 PM
Amr Ali Ebeid
Amr Ali Ebeid - avatar
9 Answers
+ 1
SFAH just observer the value of i with every loop iteration, i is decreasing , you need to increase the value of i as written by all of us 👍.
13th Jun 2022, 3:20 PM
NonStop CODING
NonStop CODING - avatar
+ 3
i = 0 while i < 5: i -= 1 #bug
12th Jun 2022, 10:47 PM
Solo
Solo - avatar
+ 3
variable "i" value is initialized zero. In while loop at end, you wrote i-=1 it should be i+=1 so that 0 can get increment to 5 and break the loop.
13th Jun 2022, 12:56 AM
Saikumar Hangal
Saikumar Hangal - avatar
+ 1
Ti Ger V2 your loop is infinite loop since the value of "i" will never go beyond 5. Because as everyone have said "i-=1" will decrease the value of loop variable. Which means as the loop will proceed its value will be -1,-2,-3 and so on which is less than 5. Therefore to avoid it you should use "i+=1". This will increase value of "i" like 1,2,3 so on till the condition of loop is satisfied.
13th Jun 2022, 8:49 AM
Sanjyot21
Sanjyot21 - avatar
0
Ti Ger V2 at line 8, increment i by 1 ✔️, i = i + 1 do not decrement i by 1 ❌, i = i - 1 is wrong Note: In python i += 1 way of incrementing a number will not work you must right i = i + 1 ✔️✔️✔️
13th Jun 2022, 2:49 AM
NonStop CODING
NonStop CODING - avatar
- 2
لم افهم
13th Jun 2022, 11:24 AM
SFAH
SFAH - avatar
- 2
I don't understand
13th Jun 2022, 11:24 AM
SFAH
SFAH - avatar
- 2
Yep i was decreasing not increasing Thank u all ❤️
13th Jun 2022, 8:25 PM
Amr Ali Ebeid
Amr Ali Ebeid - avatar
- 3
??
12th Jun 2022, 10:50 PM
Amr Ali Ebeid
Amr Ali Ebeid - avatar