next up previous
Next: The foreach statement Up: Further Perl Programming Previous: The for statement

The while/until statement

The while statement is as follows:

while (expression)
  { # while expression is true execute this block

      statement(s);
  }

For example:

i = 1;
while (  $i <= 10 )
  { # count to 10
     print "$i\n";
     ++$i;
  }

The until statement says do while expression is false as declared is as follows:

until (expression)
  { # until expression is false execute this block

      statement(s);
  }

For example:

i = 1;
until (  $i > 10 )
  { # count to 10
     print "$i\n";
     ++$i;
  }



Dave Marshall
9/28/2001