next up previous contents
Next: The foreach statement Up: If/Unless statement 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 (count_while.pl):

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 (count_until.pl):

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



dave@cs.cf.ac.uk