官术网_书友最值得收藏!

The while loop

Another syntax is the while loop. This is kind of a standard looping syntax that you see in most languages:

x = 0
while (x < 10):
print (x),
x += 1

The output of the previous code is as follows:

0 1 2 3 4 5 6 7 8 9

We can also say, start with x = 0, and while (x < 10):, print it out and then increment x by 1. This will go through over and over again, incrementing x until it's less than 10, at which point we break out of the while loop and we're done. So it does the same thing as this first example here, but just in a different style. It prints out the numbers 0 through 9 using a while loop. Just some examples there, nothing too complicated. Again, if you've done any sort of programming or scripting before, this should be pretty simple.

Now to really let this sink in, I've been saying throughout this entire chapter, get in there, get your hands dirty, and play with it. So I'm going to make you do that.

主站蜘蛛池模板: 清河县| 苏尼特右旗| 闸北区| 西城区| 拜泉县| 肥东县| 微山县| 呼伦贝尔市| 通城县| 徐州市| 香格里拉县| 灌阳县| 梁河县| 淮南市| 剑川县| 甘谷县| 沙洋县| 福安市| 阿鲁科尔沁旗| 景泰县| 合作市| 邵东县| 昭觉县| 南木林县| 永新县| 丹棱县| 大石桥市| 涿州市| 浙江省| 万宁市| 肃北| 合肥市| 界首市| 广水市| 周宁县| 靖安县| 宾川县| 兰州市| 合肥市| 交城县| 贡嘎县|