BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Loops and loop control statements in Perl

Last Updated: May 15, 2017 by Chaitanya Singh | Filed Under: Perl

Loops are used for executing a set of statements repeatedly until a particular condition is satisfied. In perl we have following loop constructs. Click on the links below to read them in detail with examples.

  • for loop: A “For” Loop is used to repeat a statement or set of statements, a known number of times. For example, if we want to display the numbers from 1 to 10 then we can use for loop that would execute 10 times. When the number of times is not known before hand, we use a “While” loop.
  • while loop: As mentioned above, when we do not know before hand that how many times we need to repeat the loop then we prefer to use while loop.
  • do-while loop: It is similar to while loop, however there is a difference between them, while loop executes the set of statements inside it after evaluating the condition. whereas do-while executes the set of statements first and then evaluates the condition. That is why we prefer do-while loop when we need to execute a block of statements at least once.
  • foreach loop: This loop is usually used when we need to iterate arrays
  • until loop: This loop behaves just opposite to the while loop. It executes the block of statements until the given condition returns true.
❮ PreviousNext ❯

Top Related Articles:

  1. Until loop in Perl with example
  2. given-when-default statement in Perl
  3. Perl – foreach loop with example
  4. For loop in Perl with example
  5. While loop in Perl with example

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Perl Tutorial

  • Perl Tutorial
  • Perl Installation
  • First Perl Program
  • Perl Syntax
  • Data types in Perl
  • Perl Variables
  • my keyword
  • Perl Scalars
  • Use strict and use warnings
  • Perl Arrays
  • Perl Hashes
  • Operators in Perl
  • Perl Conditional statements
  • Perl if
  • Perl if-else
  • Perl if-elsif-else
  • Perl unless
  • Perl unless-else
  • Perl unless-elsif-else
  • Perl switch case
  • Perl given-when-default
  • Perl loops
  • Perl subroutines
  • Perl Strings
  • Perl Escape Sequences

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap