next up previous contents index
Next: Conditionals Up: Loops Previous: Simple for () {}   Contents   Index


while () {}

The while form of a loop is also available:
  count = 10;
  while (count > 0) {
     printf("count is now %d\n", count);
     count--;
  }
Here, the statements occuring within the enclosing left and right curly braces are executed while the statement within the enclosing round brackets defining the loop is true.

The do {} while() form is also available:

  count = 10;
  do {
     printf("count is now %d\n", count);
     count--;
  } while (count > 0);

In Perl, the last and next statements can be used to, respectively, prematurely break or continue on to the next iteration within a loop. In C, the correponding statements are break and continue.