Perl Занятие 5
Оператор if if (EXPR) BLOCK else BLOCK if (EXPR) BLOCK elsif (EXPR) BLOCK. . . else BLOCK
Оператор if
Оператор unless (EXPR) BLOCK else BLOCK unless (EXPR) BLOCK elsif (EXPR) BLOCK. . . else BLOCK
Оператор unless
Оператор while LABEL while (EXPR) BLOCK continue BLOCK
Оператор while
Оператор while $a = 10; while( $a < 20 ){ printf "Value of a: $an"; $a = $a + 1; }
Оператор while $i = 1; while ($i < 10) {. . . } continue { $i++; }
Оператор until LABEL until (EXPR) BLOCK continue BLOCK
Оператор until
Оператор until $a = 5; until( $a > 10 ){ printf "Value of a: $an"; $a = $a + 1; }
Оператор for LABEL for (EXPR; EXPR) BLOCK LABEL for VAR (LIST) BLOCK continue BLOCK
Оператор for
Оператор for ($i = 1; $i < 10; $i++) {. . . }
Оператор for $elem (@elements) { $elem *= 2; }
Оператор for $count (reverse(1. . 10), "BOOM") { print $count, "n"; sleep(1); }
Оператор for (1. . 15) { print "Merry Christmasn"; }
Оператор for ($count = 10; $count >= 1; $count--) { print "$count "; }
Оператор for( ; ; ) { printf "This loop will run forever. n"; }
Оператор for( $a = 10; $a < 20; $a = $a + 1 ){ print "value of a: $an"; }
Оператор foreach LABEL foreach (EXPR; EXPR) BLOCK LABEL foreach VAR (LIST) BLOCK continue BLOCK
Оператор foreach
Оператор foreach @list = (2, 20, 30, 40, 50); foreach $a (@list){ print "value of a: $an"; }
Блоки операторов LABEL BLOCK continue BLOCK
Блоки операторов @numbers = (1, 2, 3, 4, 5); $count = 5; MYLABEL: { print $count, "n"; next if $count-- == 0; print $count, "n"; $_++ foreach @numbers; redo; } continue { print "@numbers = (@numbers)n"; } print "that's alln";
Блоки операторов @numbers = (6 7 8 9 10) that's all
Оператор do…while do{ printf "Value of a: $an"; $a = $a + 1; } while( $a < 20 );
Оператор do…while
abcbdaaabdcdb aaaa bbbb cc ddd