1.15. C # cycle

发布时间 : 2025-10-25 13:34:38 UTC      

Page Views: 9 views

Sometimes, you may need to execute the same piece of code multiple times. Ingeneral, statements are executed sequentially: the first statement in the function is executed first, then the second statement, and so on.

Programming languages provide a variety of control structures that allow formore complex execution paths.

Loop statements allow us to execute a statement or group of statements multiple times. Here is the general form of loop statements in most programming languages:

/media/sphinx_tuto/img/loop_architecture.jpg

Cyclic structure

1.15.1. Cycle type #

C # provides the following loop types. Click the link to view the details ofeach type.

Cycle type

Description

While cycle

Repeat a statement or group of statements when a given condition is true. Ittests the condition before executing the loop body.

For/foreach cycle

Execute a sequence of statements multiple times to simplify the code for managing loop variables.

do…while cycle

Except that it tests the condition at the end of the loop body, the rest is similar to the while statement.

Nested loop

You can use one or more loops within a while, for, or do..while loop.

1.15.2. Loop control statement #

The loop control statement changes the normal sequence of execution. When execution leaves a scope, all automatic objects created in that scope are destroyed.

C # provides the following control statements. Click the link to see the details of each statement.

Control statement

Description

Break statement

Terminates the loop or switch statement, and the program flow continues to execute the next statement immediately following loop or switch.

Continue statement

Skip this cycle and start the next cycle.

1.15.3. Infinite cycle #

If the condition is never false, the loop becomes an infinite loop. for loops can be used to realize infinite loops in the traditional sense.Becausenone of the three expressions that make up the loop is required, youcan leave some conditional expressions blank to form an infinite loop.

Example #

using System; namespace Loops { class Program { static void Main(string[] args) { for (; ; ) { Console.WriteLine("Hey! I am Trapped"); } } } } 

When a conditional expression does not exist, it is assumed to be true. You can also set an initial value and an incremental expression, but in general,programmers prefer to use the for(;;) structure to represent aninfinite loop.

《地理信息系统原理、技术与方法》  97

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