Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Perl loop     - JavaScript basic types and type conversion (Programming)

- MySQL partition table Comments (Database)

- Linux FAQ - How to fix tar:Exitingwith failure status due to previous errors (Linux)

- To create a problem by the statement date comparison of the difference between MySQL and Oracle (Database)

- Oracle SDE and maintain common commands - Display space (Database)

- Linux Routine Task Scheduler (Linux)

- Internal class broadcasting needs public and static (Programming)

- When Linux Detailed time zone and common function of time (Linux)

- Practical top command (Linux)

- Ubuntu 15.04 install Complete Guide (Linux)

- Oracle GoldenGate encryption (Database)

- To set up the printer use Nagios Monitoring Server (Server)

- Detailed Linux su command to switch users Mistakes (Linux)

- Experts teach you safety precautions Linux Sniffer (Linux)

- Linux Open coredump (Linux)

- How to manage the time and date at systemd Linux systems (Linux)

- CentOS7 installation hardware monitoring for Zabbix enterprise applications (Server)

- Xshell upload files to achieve Windows host Linux (Linux)

- Linux Nginx FastDFS integration module is installed Nginx and FastDFS (Server)

- Linux system performance monitoring with Nmon (Linux)

 
         
  Perl loop
     
  Add Date : 2017-09-18      
         
         
         
  While loop syntax:

while (some_expression) {
 statment_1;
 statment_2;
 ....
}

When the program executes the statement while, first check the control statements (some_expression), if it is true, the loop body will be executed once, so repeated constantly perform, know the control statement is false, then stop while cycling

Example:

#! / Usr / bin / perl -w
$ Number = 10;

while ($ number> 0) {
 print ( "number is $ number \ n");
 - $ Number;
}

until loop syntax

until (some_expression) {
 statment_1;
 statment_2;
 ...
}

And while statements contrary, some_expression false the loop body is executed, that is true stop the loop
Example:


#! / Usr / bin / perl -w
$ Number = 10;


until ($ number < = 0) {
 print ( "number is $ number \ n");
 - $ Number;
}

do while loop and do until loop syntax

do while or do until loop the loop executed at least once before the condition is checked.

do {
 statment_1;
 statment_2;
 ...
} While (some_expression);

do while loop, the conditional expression is false then the loop ends

do {
 statment_1;
 statment_2;
 ...
} Until (some_expression);

do until loop, the conditional expression is true then the end of the loop

for loop
for statement is mainly used to determine the number of cycles, the syntax is as follows:

for (in fact statement; test statement; stepping statement) {
 statment_1;
 statment_2;
 ....
}

First, the system will perform the initial statement. Usually you can assign values to variables here, but this is not mandatory, or even nothing to write, but to write or semicolon. If the value of the test the statement is true, the loop is executed once, then execute step statement.

foreach loop

foreach loop can receive a list, which will be assigned to a primary data as a parameter of a scalar variable, and the implementation of an effective assignment of each block of code statements. Its syntax is as follows:

foreach $ i (@some_list) {
 statment_1;
 statment_2;
 ....
}

Example:

#! / Usr / bin / perl -w

foreach (1..10) {
 print "";
 print;
}

print "\ n";

Leaping list any statement foreach list is used, not necessarily the array variable, you can not even write a scalar variable, so perl using the default variable $ _. If you do not specify any value to print, it will print out the contents of $ _.

If the list of values should be used where the use of a real variable, the function returns a list of substitution, then perl will be used in a loop to pass variables as aliases variables, rather than just copy values only. Thus, if you change the scalar variable in a loop, the corresponding element in the list will be changed accordingly. E.g:


#! / Usr / bin / perl -w


@ X = (1..10);
foreach $ num (@x) {
 
 $ Num + = 10;
}
print "@x";
print "\ n";

foreach after the implementation, the value of the array @x changed.
     
         
         
         
  More:      
 
- The relationship between UNIX and Linux (Linux)
- 25 Git Usage Tips (Linux)
- Linux kernel source tree to establish load module hello (Linux)
- Manually create Oracle Database Explanations (Database)
- Analytical Ceph: handle network layer (Server)
- Ubuntu 15.10 under Python + Apache + CGI fully configured (Server)
- Linux usage in echo (Linux)
- Ubuntu derivative version of the user and how to install SmartGit / HG 6.0.0 (Linux)
- Linux System Getting Started Tutorial: Installing Git on Linux (Linux)
- VMWare virtual machine without rebooting way to add virtual disk (Linux)
- Learning the Linux powerful network management capabilities (Linux)
- Compile Android libwebcore.so error occurs when solving (Programming)
- Linux based serial programming (Programming)
- Replace font under Linux (Linux)
- JavaScript in this usage (Programming)
- 6 common PHP security attacks (Linux)
- Oracle in the add & split partition on the impact of global & local index (Database)
- Redhat 7 modify the default run level method --RHEL7 use systemd to create a symbolic link to the default runlevel (Linux)
- Security Configuration SQL Server 2000 database tutorial (Linux)
- C # Future: Method Contract (Programming)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.