·  PERL – Syntax – Conditional Statements –  while

 

- Info:

  - This tutorial shows how to use while conditional statement.

  - If the condition is initially false, the body of loop will never execute.

 

- Procedure:

  - Create "PERL Application" Test.pl.

 

    Test.pl

    #SIMPLE. Output:12345.

    $i = 0;

    while($i<=4) {     

      $i++;

      print($i);

    }

    

    #LAST.  Output:12 since we break out of for loop when $i=3.

    $i = 0;       

    while($i<=4){

      $i++;

      if($i==3) { last; }

      print($i);

    }

    

    #NEXT. Output:1245 since display of number 3 is skipped.

    $i = 0

    while($i<=4){

      $i++;

      if($i==3) { next; }

      print($i);

    }