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

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.

主站蜘蛛池模板: 曲周县| 利辛县| 合江县| 天津市| 南城县| 左贡县| 泸水县| 尉犁县| 临泽县| 常德市| 大田县| 龙井市| 亳州市| 滨海县| 长春市| 福贡县| 灌云县| 桃园市| 抚顺市| 安陆市| 舒兰市| 石狮市| 晋宁县| 嘉善县| 娱乐| 富源县| 伊通| 墨江| 砀山县| 上饶市| 永丰县| 沅江市| 太仓市| 乌鲁木齐县| 濉溪县| 崇阳县| 上杭县| 巫山县| 南投市| 伊宁市| 韶关市|