"Carry on My Wayward Son"

We cover this next feature of C more for completeness than in the expectation that you'll be using it much at the introductory level. We are dealing with the continue statement. This statement causes a loop to immediately skip to the next iteration of the loop. That is, it will skip any of the rest of the body and move directly to the condition on the while or do-while statements or to expression 3 of the for statement. This is where the for statement differs slightly from it's "equivalent" while sequence.

As an example, consider the following code fragment:


for(i = 0; i < 100; i++) {
   if(prime(i))
      continue;
   ...
}

where we have a function somewhere called prime that returns a true or false indication of whether or not its argument is a prime number. (In case you don't remember what a prime number is, it's a number with no divisors except 1 and itself.) This loop will perform the code in the ... only on those numbers that are composite (not prime).

We're not going to look at the continue statement further here. This is because in most cases it's simply not needed. You can generally structure your loops so that you don't need to jump to the next iteration. But for those unusual cases where any other way would be messy, it's there.

Move on to the next part.