Teaching Perl control structures

A condition judging   IF (<expression The>) {     <statement_block_1>   }   ELSIF (<expression The>) {     <statement_block_2>   }   ...   the else {     <statement_block_3>   } Second, the cycle: . 1, the while loop   while (<expression>) {     <statement_block>   } 2, an until loop   an until (<expression the>) {     <statement_block>   } . 3, class C for loop , such as   for ($ COUNT =. 1; $ COUNT <=. 5; $ COUNT ++) {     # statements Inside the loop here Wallpaper Go   } the following is an example of using the comma operator in a for loop:

























    }   } Note: (1) where the loop variable localvar a local variable, if it has the value before, the loop remains after the recovery value. (2) change in the cycle of local variables, a corresponding array variable will change, such as:























  = @list (1, 2,. 3,. 4,. 5);
  the foreach $ TEMP (@list) {
    IF (TEMP $ == 2) {
      $ 20 is TEMP =;
    }
  }
In this case @list has become a (1, 20, 3, 4, 5).
5, do loop
  do {
    statement_block
  } while_or_until (condexpr);
  do loop executes at least one cycle.
6, the control loop
  exits the loop as Last, the role of the break of the same C; the next cycle of execution of a next, and C continue the same effect; PERL a specific command is the redo, meaning the cycle is repeated, i.e., the cycle variables constant, cycle back to the starting point, but to pay attention, redo commands do not work in cycles.
7, the traditional goto label; statement.

Third, the single-line condition   syntax statement keyword condexpr. Wherein the keyword may be if, unless, while, or until, as:     Print IF ($ var == 0); ( "This IS ZERO \ n-.")     Print ( "This IS ZERO \ n-.") The unless ($ var! = 0);



    Print (. "Not yet ZERO \ n-") the while ($ var--> 0);
    Print an until ($ var-- == 0) ( "Not yet ZERO \ n-.");
  while condition determination written on the back, but it is the first execution.

Reproduced in: https: //www.cnblogs.com/licheng/archive/2009/11/02/1594631.html

Guess you like

Origin blog.csdn.net/weixin_34245749/article/details/92632264