Continue statement is used for continuing a loop when an unexpected condition occurs. Basically this statement helps in passing control to the beginning of the loop.
Illustrates the use of continue statement.
cout<<"\n Enter the number";
cout<<"Number "<<n<<" is divisible by 5";
cout<<"The number "<<n<<" is not divisible by 5";
Input and Output:
Enter the number 10
Number 10 is divisible by 5
Enter the number 20
Number is divisible by 5
Enter the number 3
The number 3 is not divisible by 5
In the above program, initially ch is set to 'y'. The continue statement helps in transferring control to the beginning of the do .. while loop without executing the statements which follow the continue statement if the number is divisible by 5. Now a new value for the number n is entered and the process is continued as long as the number is divisible by 5. If the number is not divisible by 5, ch is set to 'n' and the program gets terminated.