Perl Control Flow Introduction (if condition, while,for loop, foreach) _perl

Source: Internet
Author: User
Tags numeric logical operators numeric value


1. Statement BLOCK:
The section between {} is block statement blocks.



2. Conditional statement:
if (expression) block;



if (expression)
BLOCK1
else BLOCK2;



if (expression1)
BLOCK1;
elsif (expression2)
BLOCK2;
Else
BLOCK3;



#Inverted if statement
Expression if (test_expression);



The relational operators involved:
numeric value Comparison: = = = =,, >=, <=,!=; note when comparing strings with numeric value comparison operators, the string is treated as 0;
String comparisons: eq, GT, lt, ge, Le, ne; (undef is treated as fake)
Logical operators: &&, | | |, and! ; and, or, not, and so on.



3. Cycle:
while (expression)
Block;
Todo



Block
while (expression);



for (initialization; test; increment)
Block;



foreach $each (@list)
Block;



4. Other

last: The final time, jump out of the current block, immediately following the block code down.
Next: This time, the next round of this block begins.
Label: similar to Goto.
Last and next are usually combined with if inverted statements or labels to achieve a jump.
Exit statement: Exit 0; End Current Perl program, return to OS;
Note: Perl does not have a switch statement, which is modeled using If-else.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.