+ 1

Hello guys some one help me explain this while loop x = 1 while x < 10: if x%2 == 0: print(str(x) + " is even")

I have failed to understand this

10th Aug 2020, 8:08 AM
Akatwijuka Allan
Akatwijuka Allan - avatar
3 Answers
+ 2
Ohh now i get it the code will make an infinite loop until when the condition remains true.
15th Sep 2020, 8:28 PM
Akatwijuka Allan
Akatwijuka Allan - avatar
+ 3
There appears to be an error in your code. x does not appear to be incremented, resulting in an infinite loop. I believe your code is supposed to: for numbers 1-10 (inclusive; interval [1, 10]), if x mod 2 is equal to zero (if x is even) print {x} is even.
10th Aug 2020, 8:12 AM
Brian R
Brian R - avatar
+ 2
That makes an infinite loop. Did you miss something?
10th Aug 2020, 8:12 AM
Alex
Alex - avatar