5.24. Perl loop nesting

发布时间 : 2025-10-25 13:33:00 UTC      

Page Views: 9 views

Perl language allows the use of another loop within one loop, and here are a few examples to illustrate this concept.

5.24.1. Grammar #

Nesting for syntax of the loop statement:

for(init;condition;increment){for(init;condition;increment){statement(s);}statement(s);} 

Nesting while syntax of the loop statement:

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

Nesting do...while syntax of the loop statement:

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

Nesting until the syntax of the loop statement:

until(condition){until(condition){statement(s);}statement(s);} 

Nesting foreach syntax of the loop statement:

foreach$a(@listA){foreach$b(@listB){statement(s);}statement(s);} 

Example #

#!/usr/bin/perl$a=0;$b=0;# outer loop while($a<3 b='$b\\n";$b=$b+1;}$a=$a+1;print"a' ){$b=0;# < =$a\\n\\n";} circulation internal pre while($b<3){print"a=$a,>   

Execute the above program, and the output is as follows:

a = 0, b = 0 a = 0, b = 1 a = 0, b = 2 a = 1 a = 1, b = 0 a = 1, b = 1 a = 1, b = 2 a = 2 a = 2, b = 0 a = 2, b = 1 a = 2, b = 2 a = 3 
《地理信息系统原理、技术与方法》  97

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