Perl Nested Loops
# Perl Nested Loops
[ Perl Loops](#)
Perl language allows using one loop inside another loop. The following examples demonstrate this concept.
### Syntax
Syntax for nested for loop statement:
for(init; condition; increment){for(init; condition; increment){statement(s); }statement(s); }
Syntax for nested while loop statement:
while(condition){while(condition){statement(s); }statement(s); }
Syntax for nested do...while loop statement:
do{statement(s); do{statement(s); }while(condition); }while(condition);
Syntax for nested until loop statement:
until(condition){until(condition){statement(s); }statement(s); }
Syntax for nested foreach 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; # inner loop while($b<3){print"a = $a,
YouTip