The continue
instruction causes the program to skip the rest of the loop in the present
iteration as if the end of the statement
block would have been reached, causing it to jump to the following iteration.
For example, we are going to skip the number 5 in our countdown:
// Continue loop example
#include <iostream.h>
int main ()
{
for (int n=10; n>0; n--) {
if (n==5) continue;
cout << n << ", ";
}
cout << "FIRE!";
return 0;
}
Output:
10,
9, 8, 7, 6, 4, 3, 2, 1, FIRE!
No comments:
Post a Comment