[英]I got different results for a while loop and for loop in python (check the codes)
[英]Undertanding the disimilarities between 2 similar codes with different results in python while loop
在第 13 行增加x
,然后在第 14 行打印x+1
。
因此,您在循环的每次迭代中得到两个打印,以及 X=6 的 output (据我了解,这里有什么困扰您)。
您可以更改代码以在 while 循环结束后进行额外打印:
x = 0
while x < 5:
print("Not yet there, X=" + str(x))
x += 1
print("X=" + str(x))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.