- Julia 1.0 Programming Complete Reference Guide
- Ivo Balbaert Adrian Salceanu
- 154字
- 2021-06-24 14:21:46
while loops
When you want to use looping as long as a condition stays true, use the while loop, which is as follows:
a = 10; b = 15 while a < b # body: process(a) println(a) global a += 1 end # prints on consecutive lines: 10 11 12 13 14
In the body of the loop, something has to change the value of a so that the initial condition becomes false and the loop ends. If the initial condition is false at the start, the body of the while loop is never executed. The global keyword makes a in the current scope refer to the global variable of that name.
If you need to loop over an array while adding or removing elements from the array, use a while loop, as follows:
arr = [1,2,3,4] while !isempty(arr) print(pop!(arr), ", ") end
The preceding code returns the output as 4, 3, 2, 1.
推薦閱讀
- Java異步編程實戰(zhàn)
- Delphi程序設計基礎:教程、實驗、習題
- C語言程序設計案例教程(第2版)
- Learning Data Mining with Python
- MATLAB 2020 從入門到精通
- Java 9 Programming Blueprints
- C和C++游戲趣味編程
- 0 bug:C/C++商用工程之道
- AutoCAD 2009實訓指導
- Julia 1.0 Programming Complete Reference Guide
- UML2面向對象分析與設計(第2版)
- Visual FoxPro 6.0程序設計
- RESTful Web Clients:基于超媒體的可復用客戶端
- Python機器學習開發(fā)實戰(zhàn)
- Data Manipulation with R(Second Edition)