Nesting Nesting Nesting Nesting Nesting Execute the above program, and the output is as follows:
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 #
for
syntax of the loop statement:for(init;condition;increment){for(init;condition;increment){statement(s);}statement(s);}
while
syntax of the loop statement:while(condition){while(condition){statement(s);}statement(s);}
do...while
syntax of the loop statement:do{statement(s);do{statement(s);}while(condition);}while(condition);
until
the syntax of the loop statement:until(condition){until(condition){statement(s);}statement(s);}
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=0;#
Internal circulation while($b<3){print"a =$a, b =$b\\n";$b=$b+1;}$a=$a+1;print"a
=$a\\n\\n";}
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