0

While loop issue on Sublime

Hi everyone, I installed Python 3.6 and using Sublime Text 3 as IDE and build platform. When I run this example: x = 5 while (x <= 5): print(x) x+=1 Result is: 5 [Finished in 0.1s] It should print the numbers from 1 to 5. What could be the problem? Regards.

18th Dec 2017, 12:42 PM
Mehmet Ali
Mehmet Ali - avatar
2 Antworten
+ 1
There is no problem, the result is effectively 5. It you want to output numbers from 1 to 5, you have to initialize x to 1, not 5 ;)
18th Dec 2017, 12:51 PM
Corentin
Corentin - avatar
+ 1
Dear Corentin, Thanks for your reply. It is really funny when you make this kind of typo and wait for the code run as you wish :) Cheers!
18th Dec 2017, 1:17 PM
Mehmet Ali
Mehmet Ali - avatar