- Hands-On Data Science and Python Machine Learning
- Frank Kane
- 190字
- 2021-07-15 17:15:04
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.
- 在最好的年紀學Python:小學生趣味編程
- Visual C++串口通信開發入門與編程實踐
- 零基礎學Scratch少兒編程:小學課本中的Scratch創意編程
- 你不知道的JavaScript(中卷)
- Python貝葉斯分析(第2版)
- MongoDB權威指南(第3版)
- jQuery炫酷應用實例集錦
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- Statistical Application Development with R and Python(Second Edition)
- 深入理解C指針
- R語言數據挖掘:實用項目解析
- 零基礎學C++(升級版)
- Drupal 8 Development:Beginner's Guide(Second Edition)
- 數字媒體技術概論
- HTML5 WebSocket權威指南