8.12. Scala do…while cycle

发布时间 :2023-11-14 23:00:02 UTC      

Not like the while loop tests the loop condition in the loop header, inthe Scala language do...while a loop checks its condition at the end of the loop.

do...while cycle and the while loop is similar, but the do...while loop ensures that the loop is executed at least once.

8.12.1. Grammar #

In Scala language the while syntax of the loop:

do {
   statement(s);
} while( condition );

8.12.2. Flow chart #

Image0

Notice that the conditional expression appears at the end of the loop, so the statement(s) will be executed at least once before the conditionis tested.

If the condition is the true control flow will jump back to the above do and then re-execute the statement(s) .

This process is repeated over and over again until a given condition becomes``false`` so far.

8.12.3. Example #

Example #

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

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

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.