8.11. Scala while cycle

发布时间 : 2025-10-25 13:35:12 UTC      

Page Views: 10 views

As long as the given condition is true in the Scala language while loop statement repeats the block of code inside the loop.

8.11.1. Grammar #

In Scala language the while syntax of the loop:

while(condition) { statement(s); } 

Here, statement(s) can be a single statement or a block of code madeup of several statements.

condition can be any expression, or when it is any non-zero value true . When the condition is the true loop is executed when the. When the condition is false to exit the loop, and the program flow continues to execute the next statement immediately following the loop.

8.11.2. Flow chart #

Image0

Here, the while key point of a loop is that the loop may not be executed at all. When the condition is false skips the loop body and directly executes the following the while next statement of the loop.

8.11.3. Example #

Example #

object Test { def main(args: Array[String]) { // local variable var a = 10; // while Recurrent execution while( a < 20 ){ println( "Value of a: " + a ); a = a + 1; } } } 

The output result of executing the above code is:

$ scalac Test.scala $ scala Test value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。