1 / 18

IT441 Network Services Administration

IT441 Network Services Administration. Prof. Alfred J Bird, Ph.D., NBCT abird@cs.umb.edu http :// it441-s14-bird.wikispaces.umb.edu / Door Code for IT441 Students – 536587* Office – McCormick 3rd floor 607 Office Hours – Tuesday and Thursday 4:00pm to 5:15pm. Ways to get out of a program.

laird
Download Presentation

IT441 Network Services Administration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IT441Network Services Administration Prof. Alfred J Bird, Ph.D., NBCT abird@cs.umb.edu http://it441-s14-bird.wikispaces.umb.edu/ Door Code for IT441 Students – 536587* Office – McCormick 3rd floor 607 Office Hours – Tuesday and Thursday 4:00pm to 5:15pm

  2. Ways to get out of a program • exit (0); • die $string;

  3. Increment/Decrement • A very helpful construct is the increment/decrement statement • $i++ is equivalent to $i = $i+1 • $j = $i++ • $j = ++$i • $j = $i - - • $j = - - $i

  4. Arithmetic Comparisons • $x > $y • $x < $y • $x >= $y • $x < =$y • $x == $y • $x != $y

  5. String Comparisions • $x gt $y • $x lt $y • $x ge $y • $x le $y • $x eq $y • $x ne $y

  6. Logical Operators • $x and &y • $x && $y • $x or $y • $x || $y • not $x • !$x

  7. Control Flow Constructs • What is a control statement? • Types of control statements: • if • while • for

  8. If Statements • if • if ( condition ) { action } • if else • if (condition ) { action } • else {another action } • if elsif else • if ( condition ) { action } • elsif (another condition ) { another action } • … • else { a further action }

  9. If Statements Practice • Write a short program to: • Read in a number • Test if it is zero, even or odd • Print out the result

  10. If Statements (cont) • unless statement unless (condition) {action}; • Reversed order print “Hello Al\n” if($inputName = “Al”); die “Can’t divide by zero\n:” if ($num4 == 0);

  11. While Statement • while loops • while ( condition ) { action } • $i=1; • while ($i<=5) { • print $i, “\n”; • $i++; • } • until loops • Same form but opposite action of the while loop

  12. While Statement Exercise • Write a short program using a while loop to: • Print out the integers from -5 to 5 • Modify the program to use an until loop

  13. An interesting variable • $_ is the default variable for many functions • while ( $line = <STDIN>) { • chomp ($line); • … • } • while (<STDIN>) { • chomp; • … • }

  14. Breaking Out of a Loop • There are three ways to modify the execution of the loop: • last; • next; • redo; • Statement labels • Labels a location in the program • Best to use all uppercase letters OUTER: while(…) { … }

  15. Another Form of Loops • do { action } while ( condition ); • do { action } until ( condition );

  16. For statement • for loop • for ( init_exp ; test_exp; step_exp) { action } • for ($i=1; $i<5; $i++) {print $i, “\n”;}

  17. Foreach loop • foreach my $number (1..10) { • print “The number is: $number \n”; • }

  18. For next time • Read Chapter 3 “Control Flow Constructs” pp 53-79 • Exercises 1, 2 & 3 on page 79

More Related