jagomart
digital resources
picture1_Perl Pdf 188286 | Damianperl2


 149x       Filetype PDF       File size 0.23 MB       Source: www.math.lsa.umich.edu


File: Perl Pdf 188286 | Damianperl2
iterating in perl loops computers are great for doing repetitive tasks all programming languages come with some way of iterating over some interval these methods of iteration are called loops ...

icon picture PDF Filetype PDF | Posted on 02 Feb 2023 | 2 years ago
Partial capture of text on file.
                                  Iterating in Perl: Loops
           -    Computers are great for doing repetitive tasks.
           -    All programming languages come with some way of iterating
                over some interval.
           -    These methods of iteration are called ‘loops’.
           -    Perl comes with a variety of loops, we will cover 4 of them:
                1. if statement and if-else statement
                2. while loop and do-while loop
                3. for loop
                4. foreach loop
                 if statement
   Syntax:          - if the conditional is ‘true’ then the
   if(conditional)  body of the statement (what’s in
   {                between the curly braces) is
     …some code…    executed.
   }
   #!/usr/bin/perl -w
   $var1 = 1333;            Output?
   if($var1 > 10)         1333 is greater than 10
   {
     print “$var1 is greater than 10\n”;
   }
   exit;
                if-else statement
   Syntax:           -if the conditional is ‘true’ then execute
   if(conditional)   the code within the first pair of curly
   {                 braces.
     …some code…
   }                 - otherwise (else) execute the code in
   else              the next set of curly braces
   {
     …some different code…
   }
                               Output?
   #!/usr/bin/perl -w       13 is less than 100
   $var1 = 13;
   if($var1 > 100)
   {
     print “$var1 is greater than 100\n”;
   }
   else
   {
     print “$var1 is less than 100\n”;
   }
   exit;
                      Comparisons that are Allowed
      - In perl you can compare numbers and strings within conditionals
      - The comparison operators are slightly different for each one
      - The most common comparison operators for strings:
        syntax  meaning                   example
          lt    Less than                 “dog” lt “cat”    False! d > c
          gt    Greater than              “dog” gt “cat”    True! d > c
          le    Less than or equal to     “dog” le “cat”    False! d > c
          ge    Greater than or equal to  “dog” ge “cat”    True! d > c
          eq    Equal to                  “cat” eq “cat”    True! c = c
          ne    Not equal to              “cat” eq “Cat”    False! c ≠ C
The words contained in this file might help you see if this file matches what you are looking for:

...Iterating in perl loops computers are great for doing repetitive tasks all programming languages come with some way of over interval these methods iteration called comes a variety we will cover them if statement and else while loop do foreach syntax the conditional is true then body what s between curly braces code executed usr bin w var output greater than print n exit execute within first pair otherwise next set different less comparisons that allowed you can compare numbers strings conditionals comparison operators slightly each one most common meaning example lt dog cat false d c gt le or equal to ge eq ne not...

no reviews yet
Please Login to review.